From 671138274e4f55163f08a8c707eca6d93864568b Mon Sep 17 00:00:00 2001 From: MickMake Date: Fri, 28 Oct 2022 20:52:19 +1100 Subject: [PATCH] v2.3.2 - Refactor #2 --- .idea/workspace.xml | 1317 +++-------------- cmd/cmd_data.go | 42 +- cmd/cmd_mqtt.go | 2 +- .../AppService/findCodeValueList/data.go | 2 +- iSolarCloud/AppService/findPsType/data.go | 10 +- .../AppService/getAllDeviceByPsId/data.go | 2 +- .../getAllPowerDeviceSetName/data.go | 2 +- iSolarCloud/AppService/getAreaList/data.go | 4 +- .../AppService/getChnnlListByPsId/data.go | 2 +- iSolarCloud/AppService/getCloudList/data.go | 8 +- iSolarCloud/AppService/getDeviceList/data.go | 22 +- .../AppService/getDeviceModelInfoList/data.go | 10 +- .../AppService/getDeviceTypeList/data.go | 2 +- .../getFaultMsgListWithYYYYMM/data.go | 4 +- iSolarCloud/AppService/getHistoryInfo/data.go | 2 +- .../getHouseholdStoragePsReport/data.go | 66 +- .../getHouseholdStoragePsReport/struct.go | 3 +- .../AppService/getIncomeSettingInfos/data.go | 13 +- .../AppService/getInstallInfoList/data.go | 2 +- .../data.go | 4 +- .../AppService/getModuleLogTaskList/data.go | 8 +- .../AppService/getOrgListByName/data.go | 2 +- .../AppService/getOrgListForUser/data.go | 6 +- .../getPowerChargeSettingInfo/data.go | 4 +- .../getPowerDeviceModelTechList/data.go | 2 +- .../getPowerDevicePointInfo/data.go | 16 +- .../getPowerDevicePointNames/data.go | 4 +- .../getPowerDeviceSetTaskList/data.go | 70 +- .../getPowerStationBasicInfo/data.go | 107 +- .../AppService/getPowerStationData/data.go | 4 +- .../getPowerStationForHousehold/data.go | 44 +- .../AppService/getPowerStationInfo/data.go | 16 +- .../AppService/getPowerStatistics/data.go | 4 +- iSolarCloud/AppService/getPsDetail/data.go | 18 +- .../AppService/getPsDetailWithPsType/data.go | 4 +- .../AppService/getPsHealthState/data.go | 2 +- iSolarCloud/AppService/getPsList/data.go | 46 +- .../AppService/getPsListByName/data.go | 38 +- .../AppService/getPsListStaticData/data.go | 68 +- iSolarCloud/AppService/getPsReport/data.go | 118 +- iSolarCloud/AppService/getPsUser/data.go | 18 +- .../AppService/getPsWeatherList/data.go | 6 +- .../AppService/getRegionalTree/data.go | 8 +- .../getRemoteUpgradeTaskList/data.go | 2 +- iSolarCloud/AppService/getReportData/data.go | 8 +- .../getReportEmailConfigInfo/data.go | 10 +- iSolarCloud/AppService/getSysMsg/data.go | 8 +- .../AppService/getTemplateList/data.go | 2 +- iSolarCloud/AppService/getUpTimePoint/data.go | 4 +- iSolarCloud/AppService/login/auth.go | 2 +- iSolarCloud/AppService/login/data.go | 38 +- .../AppService/powerDevicePointList/data.go | 4 +- iSolarCloud/AppService/psForcastInfo/data.go | 6 +- .../AppService/queryAllPsIdAndName/data.go | 2 +- .../AppService/queryDeviceInfo/data.go | 10 +- .../AppService/queryDeviceInfoForApp/data.go | 12 +- .../AppService/queryDeviceList/data.go | 218 +-- .../AppService/queryDeviceListForApp/data.go | 12 +- .../AppService/queryMutiPointDataList/data.go | 2 +- .../AppService/queryPowerStationInfo/data.go | 54 +- .../AppService/queryPsNameByPsId/data.go | 2 +- iSolarCloud/AppService/queryPsProfit/data.go | 6 +- .../AppService/queryPsProfit/struct.go | 16 - iSolarCloud/AppService/queryUnitList/data.go | 2 +- iSolarCloud/AppService/queryUserList/data.go | 2 +- iSolarCloud/AppService/reportList/data.go | 20 +- .../WebAppService/getPsIdState/data.go | 2 +- .../getReportInfoByReportId/data.go | 62 +- .../WebAppService/getReportListByType/data.go | 53 +- .../WebAppService/getReportPsTree/data.go | 30 +- .../queryUserCurveTemplateData/data.go | 14 +- iSolarCloud/WebAppService/showPSView/data.go | 2 +- .../getMaxDeviceIdByPsId/data.go | 4 +- iSolarCloud/api/apiReflect/reflect.go | 327 ++-- iSolarCloud/api/file.go | 14 + iSolarCloud/api/nullEndpoint/data.go | 76 - iSolarCloud/api/nullEndpoint/struct.go | 434 ------ iSolarCloud/api/output/struct_output.go | 39 +- iSolarCloud/api/output/struct_table.go | 45 + iSolarCloud/api/struct_data.go | 174 +-- iSolarCloud/api/struct_point.go | 55 +- iSolarCloud/api/types.go | 7 +- iSolarCloud/api/valueTypes/datetime.go | 55 +- iSolarCloud/api/valueTypes/float.go | 4 +- iSolarCloud/api/valueTypes/ps_id.go | 167 +++ iSolarCloud/api/valueTypes/types.go | 718 +++------ iSolarCloud/api/valueTypes/uv.go | 67 + iSolarCloud/api/web.go | 5 + iSolarCloud/data.go | 567 +++++-- iSolarCloud/highlevel.go | 72 +- iSolarCloud/struct.go | 17 +- mmHa/struct.go | 4 +- 92 files changed, 2170 insertions(+), 3418 deletions(-) delete mode 100644 iSolarCloud/api/nullEndpoint/data.go delete mode 100644 iSolarCloud/api/nullEndpoint/struct.go create mode 100644 iSolarCloud/api/valueTypes/ps_id.go diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 06ed4f931..e7d9ef5ea 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,1030 +5,99 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - - - - + + + diff --git a/cmd/cmd_data.go b/cmd/cmd_data.go index 70bfa28f2..a037f96ff 100644 --- a/cmd/cmd_data.go +++ b/cmd/cmd_data.go @@ -3,9 +3,7 @@ package cmd import ( "GoSungrow/Only" "GoSungrow/iSolarCloud/api/output" - "GoSungrow/iSolarCloud/api/valueTypes" "fmt" - "github.com/MickMake/GoUnify/cmdConfig" "github.com/MickMake/GoUnify/cmdHelp" "github.com/spf13/cobra" "strings" @@ -222,41 +220,17 @@ const ( func (c *CmdData) GetEndpoints(cmd *cobra.Command, args []string) error { // endpoints string, psIds string, date string for range Only.Once { - cmds.Api.SunGrow.SetOutputType(cmd.Use) - args = cmdConfig.FillArray(5, args) + cmds.Api.SunGrow.SetOutputType(cmd.Name()) - for i := range args { - if args[i] == "." { - args[i] = "" - } - } - - var e []string - if args[argEndpoints] != "" { - e = SplitArg(args[argEndpoints]) - } - - var p []valueTypes.Integer - for _, psId := range SplitArg(args[argPsIds]) { - if psId == "" { - continue - } - p = append(p, valueTypes.SetIntegerString(psId)) - } - - d := valueTypes.SetDateTimeString(args[argDate]) - - rt := args[argReportType] - if rt == "" { - rt = "1" - } - - ftc := args[argFaultTypeCode] - // if ftc == "" { - // ftc = "1" + // args = cmdConfig.FillArray(5, args) + // for i := range args { + // if args[i] == "." { + // args[i] = "" + // } // } + // c.Error = cmds.Api.SunGrow.GetEndpoints(SplitArg(args[argEndpoints]), SplitArg(args[argPsIds]), args[argDate], args[argReportType], args[argFaultTypeCode]) - c.Error = cmds.Api.SunGrow.GetEndpoints(e, p, *d, rt, ftc) + c.Error = cmds.Api.SunGrow.GetEndpoints(SplitArg(args[argEndpoints]), args[1:]...) } return c.Error diff --git a/cmd/cmd_mqtt.go b/cmd/cmd_mqtt.go index f27c471e4..50eb3a2ea 100644 --- a/cmd/cmd_mqtt.go +++ b/cmd/cmd_mqtt.go @@ -353,7 +353,7 @@ func (ca *Cmds) MqttCron() error { } for _, endpoint := range All { - response := data.GetByApi(endpoint, iSolarCloud.SunGrowDataRequest{ PsId: psId }) + response := data.GetByEndPointName(endpoint, iSolarCloud.SunGrowDataRequest{ PsId: &psId }) ca.Error = ca.Update(endpoint, response.Data, newDay) if ca.Error != nil { break diff --git a/iSolarCloud/AppService/findCodeValueList/data.go b/iSolarCloud/AppService/findCodeValueList/data.go index d90126edf..f3f8f3ae1 100644 --- a/iSolarCloud/AppService/findCodeValueList/data.go +++ b/iSolarCloud/AppService/findCodeValueList/data.go @@ -12,7 +12,7 @@ const Url = "/v1/commonService/findCodeValueList" const Disabled = false type RequestData struct { - CodeType string `json:"code_type" required:"true"` + CodeType valueTypes.String `json:"code_type" required:"true"` } func (rd RequestData) IsValid() error { diff --git a/iSolarCloud/AppService/findPsType/data.go b/iSolarCloud/AppService/findPsType/data.go index 1d35eb991..c2add1aee 100644 --- a/iSolarCloud/AppService/findPsType/data.go +++ b/iSolarCloud/AppService/findPsType/data.go @@ -12,7 +12,7 @@ const Url = "/v1/powerStationService/findPsType" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { @@ -46,12 +46,8 @@ func (e *EndPoint) GetData() api.DataMap { for range Only.Once { pkg := apiReflect.GetName("", *e) dt := valueTypes.NewDateTime(valueTypes.Now) - entries.StructToPoints(e.Response.ResultData, pkg, e.Request.PsId.String(), dt) - - // for _, d := range e.Response.ResultData { - // name := fmt.Sprintf("%s.%s", pkg, e.Request.PsId.String()) - // entries.StructToPoints(d, name, e.Request.PsId.String(), dt) - // } + name := pkg + "." + e.Request.PsId.String() + entries.StructToPoints(e.Response.ResultData, name, e.Request.PsId.String(), dt) } return entries diff --git a/iSolarCloud/AppService/getAllDeviceByPsId/data.go b/iSolarCloud/AppService/getAllDeviceByPsId/data.go index 879e72795..89597c91e 100644 --- a/iSolarCloud/AppService/getAllDeviceByPsId/data.go +++ b/iSolarCloud/AppService/getAllDeviceByPsId/data.go @@ -13,7 +13,7 @@ const Url = "/v1/devService/getAllDeviceByPsId" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { diff --git a/iSolarCloud/AppService/getAllPowerDeviceSetName/data.go b/iSolarCloud/AppService/getAllPowerDeviceSetName/data.go index a49388aaa..fd631ea0e 100644 --- a/iSolarCloud/AppService/getAllPowerDeviceSetName/data.go +++ b/iSolarCloud/AppService/getAllPowerDeviceSetName/data.go @@ -25,7 +25,7 @@ func (rd RequestData) Help() string { type ResultData []struct { Remark string `json:"remark"` - SetID valueTypes.Integer `json:"set_id"` + SetId valueTypes.Integer `json:"set_id"` SetName string `json:"set_name"` } diff --git a/iSolarCloud/AppService/getAreaList/data.go b/iSolarCloud/AppService/getAreaList/data.go index 272774c6d..2b89d091c 100644 --- a/iSolarCloud/AppService/getAreaList/data.go +++ b/iSolarCloud/AppService/getAreaList/data.go @@ -28,7 +28,7 @@ type ResultData struct { FaultStationCount valueTypes.Integer `json:"fault_station_count"` IsHaveEsPs valueTypes.Bool `json:"is_have_es_ps"` IsLeaf valueTypes.Bool `json:"is_leaf"` - OrgID valueTypes.Integer `json:"org_id"` + OrgId valueTypes.Integer `json:"org_id"` OrgName valueTypes.String `json:"org_name"` P83048 valueTypes.UnitValue `json:"p83048"` P83049 valueTypes.UnitValue `json:"p83049"` @@ -38,7 +38,7 @@ type ResultData struct { StationCount valueTypes.Integer `json:"station_count"` TodayEnergy valueTypes.UnitValue `json:"today_energy"` TotalEnergy valueTypes.UnitValue `json:"total_energy"` - } `json:"pageList" PointId:"page_list" PointNameFromChild:"OrgID" PointNameFromAppend:"false"` + } `json:"pageList" PointId:"page_list" PointNameFromChild:"OrgId" PointNameFromAppend:"false"` RowCount valueTypes.Integer `json:"rowCount" PointIgnore:"true"` } diff --git a/iSolarCloud/AppService/getChnnlListByPsId/data.go b/iSolarCloud/AppService/getChnnlListByPsId/data.go index 3e39fcccb..798340cd7 100644 --- a/iSolarCloud/AppService/getChnnlListByPsId/data.go +++ b/iSolarCloud/AppService/getChnnlListByPsId/data.go @@ -13,7 +13,7 @@ const Url = "/v1/devService/getChnnlListByPsId" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { diff --git a/iSolarCloud/AppService/getCloudList/data.go b/iSolarCloud/AppService/getCloudList/data.go index d693db744..f615a70df 100644 --- a/iSolarCloud/AppService/getCloudList/data.go +++ b/iSolarCloud/AppService/getCloudList/data.go @@ -25,10 +25,10 @@ func (rd RequestData) Help() string { type ResultData struct { CloudList []struct { - CloudID valueTypes.Integer `json:"cloud_id"` + CloudId valueTypes.Integer `json:"cloud_id"` CloudName string `json:"cloud_name"` GatewayURL string `json:"gateway_url"` - OrderID valueTypes.Integer `json:"order_id"` + OrderId valueTypes.Integer `json:"order_id"` ServiceURL string `json:"service_url"` Value string `json:"value"` ValueDeDe string `json:"value_de_de"` @@ -49,10 +49,10 @@ type ResultData struct { WebURL string `json:"web_url"` } `json:"cloud_list"` CurrentCloud struct { - CloudID valueTypes.Integer `json:"cloud_id"` + CloudId valueTypes.Integer `json:"cloud_id"` CloudName string `json:"cloud_name"` GatewayURL string `json:"gateway_url"` - OrderID valueTypes.Integer `json:"order_id"` + OrderId valueTypes.Integer `json:"order_id"` ServiceURL string `json:"service_url"` Value string `json:"value"` ValueDeDe string `json:"value_de_de"` diff --git a/iSolarCloud/AppService/getDeviceList/data.go b/iSolarCloud/AppService/getDeviceList/data.go index 6039d1e0c..8274275ba 100644 --- a/iSolarCloud/AppService/getDeviceList/data.go +++ b/iSolarCloud/AppService/getDeviceList/data.go @@ -13,7 +13,7 @@ const Url = "/v1/devService/getDeviceList" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { @@ -38,7 +38,7 @@ type ResultData struct { DeviceArea valueTypes.Integer `json:"device_area"` DeviceCode valueTypes.Integer `json:"device_code"` DeviceFactoryDate valueTypes.DateTime `json:"device_factory_date"` - DeviceID valueTypes.Integer `json:"device_id"` + DeviceId valueTypes.Integer `json:"device_id"` DeviceModel valueTypes.String `json:"device_model"` DeviceModelCode valueTypes.String `json:"device_model_code"` DeviceModelId valueTypes.Integer `json:"device_model_id"` @@ -65,7 +65,7 @@ type ResultData struct { P24 interface{} `json:"p24"` Posx interface{} `json:"posx"` Posy interface{} `json:"posy"` - PsId valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` PsKey valueTypes.PsKey `json:"ps_key"` RelState valueTypes.Integer `json:"rel_state"` Sn valueTypes.String `json:"sn" PointName:"Serial Number"` @@ -88,7 +88,7 @@ func (e *ResultData) IsValid() error { type Device struct { Vendor valueTypes.String - PsId valueTypes.Integer + PsId valueTypes.PsId PsKey valueTypes.PsKey DeviceName valueTypes.String DeviceProSn valueTypes.String @@ -96,7 +96,7 @@ type Device struct { DeviceType valueTypes.Integer DeviceCode valueTypes.Integer ChannelId valueTypes.Integer - DeviceModelID valueTypes.Integer + DeviceModelId valueTypes.Integer TypeName valueTypes.String DeviceState valueTypes.Integer DevStatus valueTypes.Integer @@ -117,7 +117,7 @@ func (e *EndPoint) GetDevices() Devices { TypeName: d.TypeName, DeviceProSn: d.DeviceProSn, DeviceModel: d.DeviceModel, - DeviceModelID: d.DeviceModelId, + DeviceModelId: d.DeviceModelId, DeviceName: d.DeviceName, DeviceState: d.DeviceState, DevStatus: d.DevStatus, @@ -153,14 +153,14 @@ func (e *EndPoint) GetDevicesTable() output.Table { // for _, d := range e.Response.ResultData.PageList { // _ = table.AddRow( // d.PsKey.Value(), - // d.PsID.Value(), + // d.PsId.Value(), // d.DeviceType.Value(), // d.DeviceCode.Value(), // d.ChannelId.Value(), // d.TypeName.Value(), // d.DeviceProSn.Value(), // d.DeviceModel.Value(), - // d.DeviceModelID.Value(), + // d.DeviceModelId.Value(), // d.DeviceName.Value(), // d.DeviceState, // d.DevStatus, @@ -200,14 +200,14 @@ func GetDevicesTable(data Devices) output.Table { // for _, d := range e.Response.ResultData.PageList { // _ = table.AddRow( // d.PsKey.Value(), - // d.PsID.Value(), + // d.PsId.Value(), // d.DeviceType.Value(), // d.DeviceCode.Value(), // d.ChannelId.Value(), // d.TypeName.Value(), // d.DeviceProSn.Value(), // d.DeviceModel.Value(), - // d.DeviceModelID.Value(), + // d.DeviceModelId.Value(), // d.DeviceName.Value(), // d.DeviceState, // d.DevStatus, @@ -247,7 +247,7 @@ func GetDevicesTable(data Devices) output.Table { d.TypeName.Value(), d.DeviceProSn.Value(), d.DeviceModel.Value(), - d.DeviceModelID.Value(), + d.DeviceModelId.Value(), d.DeviceName.Value(), d.DeviceState, d.DevStatus, diff --git a/iSolarCloud/AppService/getDeviceModelInfoList/data.go b/iSolarCloud/AppService/getDeviceModelInfoList/data.go index 28c422876..6dca06dda 100644 --- a/iSolarCloud/AppService/getDeviceModelInfoList/data.go +++ b/iSolarCloud/AppService/getDeviceModelInfoList/data.go @@ -3,8 +3,8 @@ package getDeviceModelInfoList import ( "GoSungrow/iSolarCloud/api" "GoSungrow/iSolarCloud/api/apiReflect" - "GoSungrow/iSolarCloud/api/valueTypes" "GoSungrow/iSolarCloud/api/output" + "GoSungrow/iSolarCloud/api/valueTypes" "fmt" "github.com/MickMake/GoUnify/Only" ) @@ -27,11 +27,11 @@ func (rd RequestData) Help() string { type ResultData []struct { ComType string `json:"com_type"` - DeviceFactoryID string `json:"device_factory_id"` + DeviceFactoryId string `json:"device_factory_id"` DeviceFactoryName string `json:"device_factory_name"` DeviceModel string `json:"device_model"` DeviceModelCode string `json:"device_model_code"` - DeviceModelID valueTypes.Integer `json:"device_model_id"` + DeviceModelId valueTypes.Integer `json:"device_model_id"` DeviceType valueTypes.Integer `json:"device_type"` IsRemoteUpgrade valueTypes.Bool `json:"is_remote_upgrade"` } @@ -89,10 +89,10 @@ func (e *EndPoint) GetPointDataTable() output.Table { d.DeviceModelCode = "" } _ = table.AddRow( - d.DeviceModelID, + d.DeviceModelId, d.DeviceType, d.ComType, - d.DeviceFactoryID, + d.DeviceFactoryId, d.DeviceFactoryName, d.DeviceModel, d.DeviceModelCode, diff --git a/iSolarCloud/AppService/getDeviceTypeList/data.go b/iSolarCloud/AppService/getDeviceTypeList/data.go index 89fa2a3c7..ac5276108 100644 --- a/iSolarCloud/AppService/getDeviceTypeList/data.go +++ b/iSolarCloud/AppService/getDeviceTypeList/data.go @@ -25,7 +25,7 @@ func (rd RequestData) Help() string { type ResultData struct { DeviceTypeList []struct { - DevListOrderID valueTypes.Integer `json:"dev_list_order_id"` + DevListOrderId valueTypes.Integer `json:"dev_list_order_id"` DeviceType valueTypes.Integer `json:"device_type"` TypeName valueTypes.String `json:"type_name"` } `json:"deviceTypeList"` diff --git a/iSolarCloud/AppService/getFaultMsgListWithYYYYMM/data.go b/iSolarCloud/AppService/getFaultMsgListWithYYYYMM/data.go index 540022df6..ba47c6261 100644 --- a/iSolarCloud/AppService/getFaultMsgListWithYYYYMM/data.go +++ b/iSolarCloud/AppService/getFaultMsgListWithYYYYMM/data.go @@ -32,8 +32,8 @@ type ResultData []struct { FaultReason valueTypes.String `json:"fault_reason"` FaultType valueTypes.Integer `json:"fault_type"` FaultTypeCode valueTypes.Integer `json:"fault_type_code"` - ID valueTypes.Integer `json:"id"` - PsID valueTypes.Integer `json:"ps_id"` + Id valueTypes.Integer `json:"id"` + PsId valueTypes.PsId `json:"ps_id"` PsKey valueTypes.PsKey `json:"ps_key"` UUID valueTypes.Integer `json:"uuid"` } diff --git a/iSolarCloud/AppService/getHistoryInfo/data.go b/iSolarCloud/AppService/getHistoryInfo/data.go index 3dad58bc8..e0a654778 100644 --- a/iSolarCloud/AppService/getHistoryInfo/data.go +++ b/iSolarCloud/AppService/getHistoryInfo/data.go @@ -14,7 +14,7 @@ const Disabled = false type RequestData struct { DateType string `json:"date_type" required:"true"` - DateID string `json:"date_id" required:"true"` + DateId string `json:"date_id" required:"true"` } func (rd RequestData) IsValid() error { diff --git a/iSolarCloud/AppService/getHouseholdStoragePsReport/data.go b/iSolarCloud/AppService/getHouseholdStoragePsReport/data.go index 3ab3ec58f..6ee6ac9f9 100644 --- a/iSolarCloud/AppService/getHouseholdStoragePsReport/data.go +++ b/iSolarCloud/AppService/getHouseholdStoragePsReport/data.go @@ -14,9 +14,9 @@ const Url = "/v1/powerStationService/getHouseholdStoragePsReport" const Disabled = false type RequestData struct { - DateID string `json:"date_id" required:"true"` + DateId string `json:"date_id" required:"true"` DateType string `json:"date_type" required:"true"` - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { @@ -123,7 +123,7 @@ type MonthData struct { ZjzzMap valueTypes.UnitValue `json:"zjzz_map"` ZjzzMapVirgin valueTypes.UnitValue `json:"zjzz_map_virgin" PointIgnore:"true"` MonthDataDayList []struct { - DateID valueTypes.Integer `json:"date_id"` + DateId valueTypes.Integer `json:"date_id"` Jthd valueTypes.Float `json:"jthd" PointUnitFrom:"JthdUnit" PointTimestampFrom:"TimeStamp"` JthdUnit valueTypes.String `json:"jthd_unit" PointIgnore:"true"` Jtyd valueTypes.Float `json:"jtyd" PointUnitFrom:"JtydUnit" PointTimestampFrom:"TimeStamp"` @@ -148,7 +148,7 @@ type MonthData struct { P83120 valueTypes.Float `json:"p83120" PointId:"p83120" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqMonth"` P83121 valueTypes.Float `json:"p83121" PointId:"p83121" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqMonth"` P83122 valueTypes.Float `json:"p83122" PointId:"p83122" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqMonth"` - PsID valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` SelfConsumptionYield valueTypes.Float `json:"self_consumption_yield" PointUnitFrom:"SelfConsumptionYieldUnit" PointTimestampFrom:"TimeStamp"` SelfConsumptionYieldUnit valueTypes.String `json:"self_consumption_yield_unit" PointIgnore:"true"` TimeStamp valueTypes.DateTime `json:"time_stamp"` @@ -185,7 +185,7 @@ type YearData struct { ZjzzMap valueTypes.UnitValue `json:"zjzz_map"` ZjzzMapVirgin valueTypes.UnitValue `json:"zjzz_map_virgin" PointIgnore:"true"` YearDataMonthList []struct { - DateID valueTypes.Integer `json:"date_id"` + DateId valueTypes.Integer `json:"date_id"` Jthd valueTypes.Float `json:"jthd" PointUnitFrom:"JthdUnit" PointTimestampFrom:"TimeStamp"` JthdUnit valueTypes.String `json:"jthd_unit" PointIgnore:"true"` Jtyd valueTypes.Float `json:"jtyd" PointUnitFrom:"JtydUnit" PointTimestampFrom:"TimeStamp"` @@ -210,7 +210,7 @@ type YearData struct { P83120 valueTypes.Float `json:"p83120" PointId:"p83120" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqYear"` P83121 valueTypes.Float `json:"p83121" PointId:"p83121" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqYear"` P83122 valueTypes.Float `json:"p83122" PointId:"p83122" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqYear"` - PsID valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` SelfConsumptionYield valueTypes.Float `json:"self_consumption_yield" PointUnitFrom:"SelfConsumptionYieldUnit" PointTimestampFrom:"TimeStamp"` SelfConsumptionYieldUnit valueTypes.String `json:"self_consumption_yield_unit" PointIgnore:"true"` TimeStamp valueTypes.DateTime `json:"time_stamp"` @@ -245,7 +245,7 @@ type TotalData struct { ZjzzMap valueTypes.UnitValue `json:"zjzz_map"` ZjzzMapVirgin valueTypes.UnitValue `json:"zjzz_map_virgin" PointIgnore:"true"` TotalDataYearList []struct { - DateID valueTypes.Integer `json:"date_id"` + DateId valueTypes.Integer `json:"date_id"` Jthd valueTypes.Float `json:"jthd" PointUnitFrom:"JthdUnit" PointTimestampFrom:"TimeStamp"` JthdUnit valueTypes.String `json:"jthd_unit" PointIgnore:"true"` Jtyd valueTypes.Float `json:"jtyd" PointUnitFrom:"JtydUnit" PointTimestampFrom:"TimeStamp"` @@ -270,7 +270,7 @@ type TotalData struct { P83120 valueTypes.Float `json:"p83120" PointId:"p83120" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqTotal"` P83121 valueTypes.Float `json:"p83121" PointId:"p83121" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqTotal"` P83122 valueTypes.Float `json:"p83122" PointId:"p83122" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqTotal"` - PsID valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` SelfConsumptionYield valueTypes.Float `json:"self_consumption_yield" PointUnitFrom:"SelfConsumptionYieldUnit" PointTimestampFrom:"TimeStamp"` SelfConsumptionYieldUnit valueTypes.String `json:"self_consumption_yield_unit" PointIgnore:"true"` TimeStamp valueTypes.DateTime `json:"time_stamp"` @@ -344,53 +344,9 @@ func (e *EndPoint) GetData() api.DataMap { for range Only.Once { pkg := apiReflect.GetName("", *e) - name := api.JoinWithDots(0, "", pkg, e.Request.PsId) - entries.StructToPoints(e.Response.ResultData, name, e.Request.PsId.String(), valueTypes.NewDateTime(valueTypes.Now)) - break - - // if e.Response.ResultData.DayData != nil { - // name := api.JoinWithDots(0, "", pkg, e.Request.PsId, "Day") - // entries.StructToPoints(*e.Response.ResultData.DayData, name, e.Request.PsId.String(), valueTypes.NewDateTime(valueTypes.Now)) - // - // // s := valueTypes.SizeOfArrayLength(e.Response.ResultData.DayData.PointData15List) - // // for i, d := range e.Response.ResultData.DayData.PointData15List { - // // name2 := api.JoinWithDots(s, "", name, i) - // // entries.StructToPoints(*e.Response.ResultData.DayData, name2, e.Request.PsId.String(), d.TimeStamp) - // // } - // } - // - // if e.Response.ResultData.MonthData != nil { - // name := api.JoinWithDots(0, "", pkg, e.Request.PsId, "Month") - // entries.StructToPoints(*e.Response.ResultData.MonthData, name, e.Request.PsId.String(), valueTypes.NewDateTime(valueTypes.Now)) - // - // // s := valueTypes.SizeOfArrayLength(e.Response.ResultData.MonthData.MonthDataDayList) - // // for i, d := range e.Response.ResultData.MonthData.MonthDataDayList { - // // name2 := api.JoinWithDots(s, "", name, i) - // // entries.StructToPoints(*e.Response.ResultData.MonthData, name2, e.Request.PsId.String(), d.TimeStamp) - // // } - // } - // - // if e.Response.ResultData.YearData != nil { - // name := api.JoinWithDots(0, "", pkg, e.Request.PsId, "Year") - // entries.StructToPoints(*e.Response.ResultData.YearData, name, e.Request.PsId.String(), valueTypes.NewDateTime(valueTypes.Now)) - // - // // s := valueTypes.SizeOfArrayLength(e.Response.ResultData.YearData.YearDataMonthList) - // // for i, d := range e.Response.ResultData.YearData.YearDataMonthList { - // // name2 := api.JoinWithDots(s, "", name, i) - // // entries.StructToPoints(*e.Response.ResultData.YearData, name2, e.Request.PsId.String(), d.TimeStamp) - // // } - // } - // - // if e.Response.ResultData.TotalData != nil { - // name := api.JoinWithDots(0, "", pkg, e.Request.PsId, "Total") - // entries.StructToPoints(*e.Response.ResultData.TotalData, name, e.Request.PsId.String(), valueTypes.NewDateTime(valueTypes.Now)) - // - // // s := valueTypes.SizeOfArrayLength(e.Response.ResultData.TotalData.TotalDataYearList) - // // for i, d := range e.Response.ResultData.TotalData.TotalDataYearList { - // // name2 := api.JoinWithDots(s, "", name, i) - // // entries.StructToPoints(*e.Response.ResultData.TotalData, name2, e.Request.PsId.String(), d.TimeStamp) - // // } - // } + dt := valueTypes.NewDateTime(valueTypes.Now) + name := pkg + "." + e.Request.PsId.String() + entries.StructToPoints(e.Response.ResultData, name, e.Request.PsId.String(), dt) } return entries diff --git a/iSolarCloud/AppService/getHouseholdStoragePsReport/struct.go b/iSolarCloud/AppService/getHouseholdStoragePsReport/struct.go index e9a618675..045aae1f3 100644 --- a/iSolarCloud/AppService/getHouseholdStoragePsReport/struct.go +++ b/iSolarCloud/AppService/getHouseholdStoragePsReport/struct.go @@ -373,7 +373,8 @@ func (e EndPoint) GetEndPointDataTable() output.Table { // SetFilenamePrefix - Produce filename based on area and endpoint name. func (e EndPoint) SetFilenamePrefix(format string, args ...interface{}) string { - return e.ApiSetFilenamePrefix(format, args...) + return e.ApiSetFilenamePrefix2(e.Request.RequestData, format, args...) + // return e.ApiSetFilenamePrefix(format, args...) } // GetRequestArgNames - diff --git a/iSolarCloud/AppService/getIncomeSettingInfos/data.go b/iSolarCloud/AppService/getIncomeSettingInfos/data.go index 8495745cd..4334f4002 100644 --- a/iSolarCloud/AppService/getIncomeSettingInfos/data.go +++ b/iSolarCloud/AppService/getIncomeSettingInfos/data.go @@ -12,7 +12,7 @@ const Url = "/v1/powerStationService/getIncomeSettingInfos" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { @@ -33,14 +33,14 @@ type ResultData struct { CodeType valueTypes.Integer `json:"code_type"` CountyAllowanceMoney interface{} `json:"county_allowance_money"` DefaultCharge valueTypes.Float `json:"default_charge"` - ElectricChargeID valueTypes.Integer `json:"electric_charge_id"` + ElectricChargeId valueTypes.Integer `json:"electric_charge_id"` EndTime valueTypes.DateTime `json:"end_time"` IncomeStyle interface{} `json:"income_style"` IntervalTimeCharge interface{} `json:"interval_time_charge"` NationAllowanceMoney interface{} `json:"nation_allowance_money"` ParamIncomeUnit valueTypes.Integer `json:"param_income_unit"` ProvinceAllowanceMoney interface{} `json:"province_allowance_money"` - PsId valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` StartTime valueTypes.DateTime `json:"start_time"` UseSharpPeekValleyFlat interface{} `json:"use_sharp_peek_valley_flat"` ValidFlag valueTypes.Bool `json:"valid_flag"` @@ -51,11 +51,11 @@ type ResultData struct { EndTime valueTypes.DateTime `json:"end_time"` IntervalTimeCharge valueTypes.String `json:"interval_time_charge"` OnlineElectricityPercent valueTypes.Float `json:"online_electricity_percent" PointUnit:"%"` - PsID valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` StartTime valueTypes.DateTime `json:"start_time"` UseElectricityDiscount valueTypes.Float `json:"use_electricity_discount" PointUnit:"%"` } `json:"powerSelfUseTimesChargeMap" PointId:"power_selfuse_times_charge_map"` - PsId valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` } func (e *ResultData) IsValid() error { @@ -75,7 +75,8 @@ func (e *EndPoint) GetData() api.DataMap { for range Only.Once { pkg := apiReflect.GetName("", *e) dt := valueTypes.NewDateTime(valueTypes.Now) - entries.StructToPoints(e.Response.ResultData, pkg, e.Request.PsId.String(), dt) + name := pkg + "." + e.Request.PsId.String() + entries.StructToPoints(e.Response.ResultData, name, e.Request.PsId.String(), dt) } return entries diff --git a/iSolarCloud/AppService/getInstallInfoList/data.go b/iSolarCloud/AppService/getInstallInfoList/data.go index b852af929..c1948f29c 100644 --- a/iSolarCloud/AppService/getInstallInfoList/data.go +++ b/iSolarCloud/AppService/getInstallInfoList/data.go @@ -29,7 +29,7 @@ type ResultData []struct { Installer string `json:"installer"` InstallerEmail string `json:"installer_email"` InstallerPhone string `json:"installer_phone"` - OrgID string `json:"org_id"` + OrgId string `json:"org_id"` PsNames []string `json:"ps_names"` } diff --git a/iSolarCloud/AppService/getInstallerInfoByDealerOrgCodeOrId/data.go b/iSolarCloud/AppService/getInstallerInfoByDealerOrgCodeOrId/data.go index 0a67bcfa8..c7e191f02 100644 --- a/iSolarCloud/AppService/getInstallerInfoByDealerOrgCodeOrId/data.go +++ b/iSolarCloud/AppService/getInstallerInfoByDealerOrgCodeOrId/data.go @@ -34,9 +34,9 @@ type ResultData struct { InstallerEmail string `json:"installer_email"` InstallerPhone string `json:"installer_phone"` MobleTel interface{} `json:"moble_tel"` - OrgID valueTypes.Integer `json:"org_id"` + OrgId valueTypes.Integer `json:"org_id"` OrgName string `json:"org_name"` - UserID valueTypes.Integer `json:"user_id"` + UserId valueTypes.Integer `json:"user_id"` UserName string `json:"user_name"` UserTelNationCode interface{} `json:"user_tel_nation_code"` } `json:"user_info_list"` diff --git a/iSolarCloud/AppService/getModuleLogTaskList/data.go b/iSolarCloud/AppService/getModuleLogTaskList/data.go index 513416438..5ffdd90ba 100644 --- a/iSolarCloud/AppService/getModuleLogTaskList/data.go +++ b/iSolarCloud/AppService/getModuleLogTaskList/data.go @@ -27,17 +27,17 @@ type ResultData struct { CurPage valueTypes.Integer `json:"curPage"` IsMore valueTypes.Bool `json:"isMore"` PageList []struct { - BatchID valueTypes.String `json:"batch_id"` + BatchId valueTypes.String `json:"batch_id"` CommandStatus valueTypes.Integer `json:"command_status"` CommandType valueTypes.Integer `json:"command_type"` CreateTime valueTypes.DateTime `json:"create_time"` DeviceCode valueTypes.Integer `json:"device_code"` DeviceModel valueTypes.String `json:"device_model"` - DeviceModelID valueTypes.String `json:"device_model_id"` + DeviceModelId valueTypes.String `json:"device_model_id"` ExpireSecond valueTypes.Integer `json:"expire_second"` LogType valueTypes.Integer `json:"log_type"` LoggerCode valueTypes.Integer `json:"logger_code"` - OperateUserID valueTypes.Integer `json:"operate_user_id"` + OperateUserId valueTypes.Integer `json:"operate_user_id"` OverTime valueTypes.DateTime `json:"over_time"` Remark valueTypes.String `json:"remark"` SetCancelNum valueTypes.Integer `json:"set_cancel_num"` @@ -47,7 +47,7 @@ type ResultData struct { SetSuccessNum valueTypes.Integer `json:"set_success_num"` SetTotalNum valueTypes.Integer `json:"set_total_num"` Sn valueTypes.String `json:"sn"` - TaskID valueTypes.Integer `json:"task_id"` + TaskId valueTypes.Integer `json:"task_id"` TaskName valueTypes.Integer `json:"task_name"` UpdateTime valueTypes.DateTime `json:"update_time"` } `json:"pageList"` diff --git a/iSolarCloud/AppService/getOrgListByName/data.go b/iSolarCloud/AppService/getOrgListByName/data.go index 08661e21c..4b396b5bb 100644 --- a/iSolarCloud/AppService/getOrgListByName/data.go +++ b/iSolarCloud/AppService/getOrgListByName/data.go @@ -26,7 +26,7 @@ func (rd RequestData) Help() string { type ResultData []struct { IsLeaf valueTypes.Bool `json:"is_leaf"` - OrgID valueTypes.Integer `json:"org_id"` + OrgId valueTypes.Integer `json:"org_id"` OrgName valueTypes.String `json:"org_name"` } diff --git a/iSolarCloud/AppService/getOrgListForUser/data.go b/iSolarCloud/AppService/getOrgListForUser/data.go index b4e66b395..92ac54f72 100644 --- a/iSolarCloud/AppService/getOrgListForUser/data.go +++ b/iSolarCloud/AppService/getOrgListForUser/data.go @@ -27,16 +27,16 @@ func (rd RequestData) Help() string { type ResultData []struct { GcjLatitude valueTypes.Float `json:"gcj_latitude"` GcjLongitude valueTypes.Float `json:"gcj_longitude"` - ID valueTypes.Integer `json:"id"` + Id valueTypes.Integer `json:"id"` IsLeaf valueTypes.Bool `json:"is_leaf"` MapLevel interface{} `json:"map_level"` - OrgID valueTypes.Integer `json:"org_id"` + OrgId valueTypes.Integer `json:"org_id"` OrgIndexCode valueTypes.String `json:"org_index_code"` OrgIsShow valueTypes.Integer `json:"org_is_show"` OrgLevel valueTypes.Integer `json:"org_level"` OrgName valueTypes.String `json:"org_name"` SizeChild valueTypes.Integer `json:"size_child"` - UpOrgID valueTypes.Integer `json:"up_org_id"` + UpOrgId valueTypes.Integer `json:"up_org_id"` Wgs84Latitude valueTypes.Float `json:"wgs84_latitude"` Wgs84Longitude valueTypes.Float `json:"wgs84_longitude"` } diff --git a/iSolarCloud/AppService/getPowerChargeSettingInfo/data.go b/iSolarCloud/AppService/getPowerChargeSettingInfo/data.go index 0c7f0761a..1b6180e4a 100644 --- a/iSolarCloud/AppService/getPowerChargeSettingInfo/data.go +++ b/iSolarCloud/AppService/getPowerChargeSettingInfo/data.go @@ -12,7 +12,7 @@ const Url = "/v1/powerStationService/getPowerChargeSettingInfo" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { @@ -35,7 +35,7 @@ type ResultData struct { DefaultCharge valueTypes.Float `json:"default_charge" PointUnitFrom:"ParamIncomeUnitName"` IntervalTimeCharge string `json:"interval_time_charge"` } `json:"powerSelfUseTimesChargeMap" PointName:"power_self_use_charge_map"` - PsID valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` } func (e *ResultData) IsValid() error { diff --git a/iSolarCloud/AppService/getPowerDeviceModelTechList/data.go b/iSolarCloud/AppService/getPowerDeviceModelTechList/data.go index 37d30b6e9..13bbe2321 100644 --- a/iSolarCloud/AppService/getPowerDeviceModelTechList/data.go +++ b/iSolarCloud/AppService/getPowerDeviceModelTechList/data.go @@ -61,7 +61,7 @@ func (rd RequestData) Help() string { } type ResultData []struct { - CodeID valueTypes.Integer `json:"code_id"` + CodeId valueTypes.Integer `json:"code_id"` CodeName string `json:"code_name"` CodeValue string `json:"code_value"` DefaultValue interface{} `json:"default_value"` diff --git a/iSolarCloud/AppService/getPowerDevicePointInfo/data.go b/iSolarCloud/AppService/getPowerDevicePointInfo/data.go index c5b497033..faf0c5360 100644 --- a/iSolarCloud/AppService/getPowerDevicePointInfo/data.go +++ b/iSolarCloud/AppService/getPowerDevicePointInfo/data.go @@ -3,8 +3,8 @@ package getPowerDevicePointInfo import ( "GoSungrow/iSolarCloud/api" "GoSungrow/iSolarCloud/api/apiReflect" - "GoSungrow/iSolarCloud/api/valueTypes" "GoSungrow/iSolarCloud/api/output" + "GoSungrow/iSolarCloud/api/valueTypes" "github.com/MickMake/GoUnify/Only" "fmt" @@ -14,7 +14,7 @@ const Url = "/v1/reportService/getPowerDevicePointInfo" const Disabled = false type RequestData struct { - Id valueTypes.Integer `json:"id" required:"true"` + PsId valueTypes.PsId `json:"id" required:"true"` // Id string `json:"id"` } @@ -30,12 +30,12 @@ func (rd RequestData) Help() string { type ResultData struct { DeviceType valueTypes.Integer `json:"device_type" PointId:"device_type" PointValueType:"" PointUpdateFreq:""` - ID valueTypes.Integer `json:"id" PointId:"id" PointValueType:"" PointUpdateFreq:""` + Id valueTypes.Integer `json:"id" PointId:"id" PointValueType:"" PointUpdateFreq:""` Period valueTypes.Integer `json:"period" PointId:"period" PointValueType:"" PointUpdateFreq:""` - PointID valueTypes.Integer `json:"point_id" PointId:"point_id" PointValueType:"" PointUpdateFreq:""` + PointId valueTypes.Integer `json:"point_id" PointId:"point_id" PointValueType:"" PointUpdateFreq:""` PointName string `json:"point_name" PointId:"point_name" PointValueType:"" PointUpdateFreq:""` ShowPointName string `json:"show_point_name" PointId:"show_point_name" PointValueType:"" PointUpdateFreq:""` - TranslationID valueTypes.Integer `json:"translation_id" PointId:"translation_id" PointValueType:"" PointUpdateFreq:""` + TranslationId valueTypes.Integer `json:"translation_id" PointId:"translation_id" PointValueType:"" PointUpdateFreq:""` } func (e *ResultData) IsValid() error { @@ -71,10 +71,10 @@ func (e *EndPoint) AddDataTable(table output.Table) output.Table { for range Only.Once { rd := e.Response.ResultData - if rd.ID.Value() == 0 { + if rd.Id.Value() == 0 { break } - _ = table.AddRow(rd.DeviceType, rd.ID, rd.Period, rd.PointID,rd.PointName, rd.ShowPointName, rd.TranslationID) + _ = table.AddRow(rd.DeviceType, rd.Id, rd.Period, rd.PointId,rd.PointName, rd.ShowPointName, rd.TranslationId) } return table } @@ -97,7 +97,7 @@ func (e *EndPoint) GetPointDataTable() output.Table { "Translation Id", ) rd := e.Response.ResultData - _ = table.AddRow(rd.DeviceType, rd.ID, rd.Period, rd.PointID,rd.PointName, rd.ShowPointName, rd.TranslationID) + _ = table.AddRow(rd.DeviceType, rd.Id, rd.Period, rd.PointId,rd.PointName, rd.ShowPointName, rd.TranslationId) } return table } diff --git a/iSolarCloud/AppService/getPowerDevicePointNames/data.go b/iSolarCloud/AppService/getPowerDevicePointNames/data.go index ca8539083..396fac4e6 100644 --- a/iSolarCloud/AppService/getPowerDevicePointNames/data.go +++ b/iSolarCloud/AppService/getPowerDevicePointNames/data.go @@ -74,7 +74,7 @@ func (rd RequestData) Help() string { type ResultData []struct { PointCalType valueTypes.Integer `json:"point_cal_type"` - PointID valueTypes.Integer `json:"point_id"` + PointId valueTypes.Integer `json:"point_id"` PointName string `json:"point_name"` } @@ -133,7 +133,7 @@ func (e *EndPoint) GetPointDataTable() output.Table { _ = table.AddRow( e.Request.DeviceType, p.PointCalType, - p.PointID, + p.PointId, p.PointName, ) if table.Error != nil { diff --git a/iSolarCloud/AppService/getPowerDeviceSetTaskList/data.go b/iSolarCloud/AppService/getPowerDeviceSetTaskList/data.go index b38d098a0..2a949e8ca 100644 --- a/iSolarCloud/AppService/getPowerDeviceSetTaskList/data.go +++ b/iSolarCloud/AppService/getPowerDeviceSetTaskList/data.go @@ -4,8 +4,8 @@ import ( "GoSungrow/iSolarCloud/api" "GoSungrow/iSolarCloud/api/apiReflect" "GoSungrow/iSolarCloud/api/valueTypes" - "github.com/MickMake/GoUnify/Only" "fmt" + "github.com/MickMake/GoUnify/Only" ) const Url = "/v1/devService/getPowerDeviceSetTaskList" @@ -27,28 +27,28 @@ func (rd RequestData) Help() string { type ResultData struct { PageList []struct { - CommandStatus valueTypes.Integer `json:"command_status"` - CommandType valueTypes.Integer `json:"command_type"` - CreateTime string `json:"create_time"` - OperateUserID valueTypes.Integer `json:"operate_user_id"` - OverTime string `json:"over_time"` - PsID valueTypes.Integer `json:"ps_id"` - SetCancelNum valueTypes.Integer `json:"set_cancel_num"` - SetFailNum valueTypes.Integer `json:"set_fail_num"` - SetFinishNum valueTypes.Integer `json:"set_finish_num"` - SetOvertimeNum valueTypes.Integer `json:"set_overtime_num"` - SetSuccessNum valueTypes.Integer `json:"set_success_num"` - SetTotalNum valueTypes.Integer `json:"set_total_num"` - SweepDevParamSetType valueTypes.Integer `json:"sweep_dev_param_set_type"` - TaskID valueTypes.Integer `json:"task_id"` - TaskName string `json:"task_name"` - TaskType valueTypes.Integer `json:"task_type"` - TemplateType valueTypes.Integer `json:"template_type"` - UpdateTime string `json:"update_time"` - UserEnglishName interface{} `json:"user_english_name"` - UserName string `json:"user_name"` - UUID valueTypes.Integer `json:"uuid"` - } `json:"pageList"` + CommandStatus valueTypes.Integer `json:"command_status"` + CommandType valueTypes.Integer `json:"command_type"` + CreateTime valueTypes.DateTime `json:"create_time"` + OperateUserId valueTypes.Integer `json:"operate_user_id"` + OverTime valueTypes.DateTime `json:"over_time"` + PsId valueTypes.PsId `json:"ps_id"` + SetCancelNum valueTypes.Count `json:"set_cancel_num"` + SetFailNum valueTypes.Count `json:"set_fail_num"` + SetFinishNum valueTypes.Count `json:"set_finish_num"` + SetOvertimeNum valueTypes.Count `json:"set_overtime_num"` + SetSuccessNum valueTypes.Count `json:"set_success_num"` + SetTotalNum valueTypes.Count `json:"set_total_num"` + SweepDevParamSetType valueTypes.Integer `json:"sweep_dev_param_set_type"` + TaskId valueTypes.Integer `json:"task_id"` + TaskName valueTypes.String `json:"task_name"` + TaskType valueTypes.Integer `json:"task_type"` + TemplateType valueTypes.Integer `json:"template_type"` + UpdateTime valueTypes.DateTime `json:"update_time"` + UserEnglishName interface{} `json:"user_english_name"` + UserName valueTypes.String `json:"user_name"` + UUID valueTypes.Integer `json:"uuid"` + } `json:"pageList" PointId:"page_list" PointNameFromChild:"PsId.CreateTime" PointNameFromAppend:"false"` RowCount valueTypes.Integer `json:"rowCount"` } @@ -63,30 +63,14 @@ func (e *ResultData) IsValid() error { return err } -// type DecodeResultData ResultData -// -// func (e *ResultData) UnmarshalJSON(data []byte) error { -// var err error -// -// for range Only.Once { -// if len(data) == 0 { -// break -// } -// var pd DecodeResultData -// -// // Store ResultData -// _ = json.Unmarshal(data, &pd) -// e.Dummy = pd.Dummy -// } -// -// return err -// } - func (e *EndPoint) GetData() api.DataMap { entries := api.NewDataMap() for range Only.Once { - entries.StructToPoints(e.Response.ResultData, apiReflect.GetName("", *e), "system", valueTypes.NewDateTime("")) + pkg := apiReflect.GetName("", *e) + dt := valueTypes.NewDateTime(valueTypes.Now) + // name := pkg + "." + e.Request.PsId.String() + entries.StructToPoints(e.Response.ResultData, pkg, "system", dt) } return entries diff --git a/iSolarCloud/AppService/getPowerStationBasicInfo/data.go b/iSolarCloud/AppService/getPowerStationBasicInfo/data.go index 3e5465efd..a83fbf395 100644 --- a/iSolarCloud/AppService/getPowerStationBasicInfo/data.go +++ b/iSolarCloud/AppService/getPowerStationBasicInfo/data.go @@ -12,7 +12,7 @@ const Url = "/v1/powerStationService/getPowerStationBasicInfo" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { @@ -24,47 +24,46 @@ func (rd RequestData) Help() string { return ret } - -type ResultData struct { - AreaID interface{} `json:"area_id"` - ConnectType valueTypes.Integer `json:"connect_type"` - County interface{} `json:"county"` - CountyCode interface{} `json:"county_code"` - DesignCapacity valueTypes.Integer `json:"design_capacity"` - Email string `json:"email"` - EnergyScheme interface{} `json:"energy_scheme"` - ExpectInstallDate valueTypes.DateTime `json:"expect_install_date"` - FaultSendType interface{} `json:"fault_send_type"` - GcjLatitude valueTypes.Float `json:"gcj_latitude"` - GcjLongitude valueTypes.Float `json:"gcj_longitude"` - Latitude valueTypes.Float `json:"latitude"` - Longitude valueTypes.Float `json:"longitude"` - Name interface{} `json:"name"` - NameCode interface{} `json:"name_code"` - Nation interface{} `json:"nation"` - NationCode interface{} `json:"nation_code"` - ParamIncome valueTypes.Integer `json:"param_income"` - Prov interface{} `json:"prov"` - ProvCode interface{} `json:"prov_code"` - PsBuildDate valueTypes.DateTime `json:"ps_build_date"` - PsCountryID valueTypes.Integer `json:"ps_country_id"` - PsDesc interface{} `json:"ps_desc"` - PsHolder string `json:"ps_holder"` - PsID valueTypes.Integer `json:"ps_id"` - PsLocation string `json:"ps_location"` - PsName string `json:"ps_name"` - PsType valueTypes.Integer `json:"ps_type"` - RecoreCreateTime string `json:"recore_create_time"` - ReportType interface{} `json:"report_type"` - ShippingAddress string `json:"shipping_address"` - ShippingZipCode string `json:"shipping_zip_code"` - TimeZoneID valueTypes.Integer `json:"time_zone_id"` - ValidFlag valueTypes.Integer `json:"valid_flag"` - Village interface{} `json:"village"` - VillageCode interface{} `json:"village_code"` - WgsLatitude valueTypes.Float `json:"wgs_latitude"` - WgsLongitude valueTypes.Float `json:"wgs_longitude"` - ZipCode string `json:"zip_code"` +type ResultData struct { + AreaId interface{} `json:"area_id"` + ConnectType valueTypes.Integer `json:"connect_type"` + County interface{} `json:"county"` + CountyCode interface{} `json:"county_code"` + DesignCapacity valueTypes.Float `json:"design_capacity"` + Email valueTypes.String `json:"email"` + EnergyScheme interface{} `json:"energy_scheme"` + ExpectInstallDate valueTypes.DateTime `json:"expect_install_date"` + FaultSendType interface{} `json:"fault_send_type"` + GcjLatitude valueTypes.Float `json:"gcj_latitude"` + GcjLongitude valueTypes.Float `json:"gcj_longitude"` + Latitude valueTypes.Float `json:"latitude"` + Longitude valueTypes.Float `json:"longitude"` + Name interface{} `json:"name"` + NameCode interface{} `json:"name_code"` + Nation interface{} `json:"nation"` + NationCode interface{} `json:"nation_code"` + ParamIncome valueTypes.Float `json:"param_income"` + Prov interface{} `json:"prov"` + ProvCode interface{} `json:"prov_code"` + PsBuildDate valueTypes.DateTime `json:"ps_build_date"` + PsCountryId valueTypes.Integer `json:"ps_country_id"` + PsDesc interface{} `json:"ps_desc"` + PsHolder valueTypes.String `json:"ps_holder"` + PsId valueTypes.PsId `json:"ps_id"` + PsLocation valueTypes.String `json:"ps_location"` + PsName valueTypes.String `json:"ps_name"` + PsType valueTypes.Integer `json:"ps_type"` + RecordCreateTime string `json:"recore_create_time"` + ReportType interface{} `json:"report_type"` + ShippingAddress valueTypes.String `json:"shipping_address"` + ShippingZipCode valueTypes.String `json:"shipping_zip_code"` + TimeZoneId valueTypes.Integer `json:"time_zone_id"` + ValidFlag valueTypes.Bool `json:"valid_flag"` + Village interface{} `json:"village"` + VillageCode interface{} `json:"village_code"` + WgsLatitude valueTypes.Float `json:"wgs_latitude"` + WgsLongitude valueTypes.Float `json:"wgs_longitude"` + ZipCode valueTypes.String `json:"zip_code"` } func (e *ResultData) IsValid() error { @@ -78,30 +77,14 @@ func (e *ResultData) IsValid() error { return err } -//type DecodeResultData ResultData -// -//func (e *ResultData) UnmarshalJSON(data []byte) error { -// var err error -// -// for range Only.Once { -// if len(data) == 0 { -// break -// } -// var pd DecodeResultData -// -// // Store ResultData -// _ = json.Unmarshal(data, &pd) -// e.Dummy = pd.Dummy -// } -// -// return err -//} - func (e *EndPoint) GetData() api.DataMap { entries := api.NewDataMap() for range Only.Once { - entries.StructToPoints(e.Response.ResultData, apiReflect.GetName("", *e), "system", valueTypes.NewDateTime("")) + pkg := apiReflect.GetName("", *e) + dt := valueTypes.NewDateTime(valueTypes.Now) + name := pkg + "." + e.Request.PsId.String() + entries.StructToPoints(e.Response.ResultData, name, e.Request.PsId.String(), dt) } return entries diff --git a/iSolarCloud/AppService/getPowerStationData/data.go b/iSolarCloud/AppService/getPowerStationData/data.go index e25a95b5e..fbb37f1e7 100644 --- a/iSolarCloud/AppService/getPowerStationData/data.go +++ b/iSolarCloud/AppService/getPowerStationData/data.go @@ -12,8 +12,8 @@ const Url = "/v1/powerStationService/getPowerStationData" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` - DateID string `json:"date_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` + DateId string `json:"date_id" required:"true"` DateType string `json:"date_type" required:"true"` } diff --git a/iSolarCloud/AppService/getPowerStationForHousehold/data.go b/iSolarCloud/AppService/getPowerStationForHousehold/data.go index a8459db78..304c69f21 100644 --- a/iSolarCloud/AppService/getPowerStationForHousehold/data.go +++ b/iSolarCloud/AppService/getPowerStationForHousehold/data.go @@ -12,7 +12,7 @@ const Url = "/v1/powerStationService/getPowerStationForHousehold" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { @@ -25,10 +25,10 @@ func (rd RequestData) Help() string { } type ResultData struct { - LbsAreaCode valueTypes.String `json:"LbsAreaCode"` - LbsCountry valueTypes.String `json:"LbsCountry"` + LbsAreaCode valueTypes.String `json:"LbsAreaCode" PointId:"lbs_area_code"` + LbsCountry valueTypes.String `json:"LbsCountry" PointId:"lbs_country"` AccessType interface{} `json:"access_type"` - AreaID interface{} `json:"area_id"` + AreaId interface{} `json:"area_id"` ArrearsStatus valueTypes.Integer `json:"arrears_status"` BatteryType valueTypes.Integer `json:"battery_type"` CityCode valueTypes.String `json:"city_code"` @@ -38,7 +38,7 @@ type ResultData struct { ConnectType valueTypes.Integer `json:"connect_type"` ConnectTypeDesc valueTypes.String `json:"connect_type_desc"` ContactName valueTypes.String `json:"contact_name"` - CountryID valueTypes.Integer `json:"country_id"` + CountryId valueTypes.Integer `json:"country_id"` Description valueTypes.String `json:"description"` DesignCapacity valueTypes.Float `json:"design_capacity" PointUnit:"W"` DesignCapacityBattery valueTypes.Float `json:"design_capacity_battery" PointUnit:"W"` @@ -53,7 +53,15 @@ type ResultData struct { GprsLatitude valueTypes.Float `json:"gprs_latitude"` GprsLongitude valueTypes.Float `json:"gprs_longitude"` GridLevel interface{} `json:"grid_level"` - Images []valueTypes.String `json:"images"` + Images []struct { + FileID valueTypes.Integer `json:"file_id"` + ID valueTypes.Integer `json:"id"` + PicLanguage valueTypes.Integer `json:"pic_language"` + PicType valueTypes.Integer `json:"pic_type"` + PictureName valueTypes.String `json:"picture_name"` + PictureURL valueTypes.String `json:"picture_url"` + PsUnitUUID interface{} `json:"ps_unit_uuid"` + } `json:"images"` InstallDate valueTypes.DateTime `json:"install_date"` InstallDateZone valueTypes.DateTime `json:"install_date_zone"` InverterCount valueTypes.Integer `json:"inverter_count"` @@ -75,7 +83,7 @@ type ResultData struct { MlpeFlag valueTypes.Bool `json:"mlpe_flag"` MobileTel valueTypes.String `json:"moble_tel"` MobileTelBak valueTypes.String `json:"moble_tel_bak"` - ModuleModelID interface{} `json:"module_model_id"` + ModuleModelId interface{} `json:"module_model_id"` ModuleModelName valueTypes.String `json:"module_model_name"` Nmi valueTypes.String `json:"nmi"` OperationBusName valueTypes.String `json:"operation_bus_name"` @@ -86,16 +94,16 @@ type ResultData struct { ProvinceCode valueTypes.String `json:"province_code"` ProvinceName valueTypes.String `json:"province_name"` PsBuildDate valueTypes.DateTime `json:"ps_build_date"` - PsCountryID valueTypes.Integer `json:"ps_country_id"` - PsCreateUserID valueTypes.Integer `json:"ps_create_user_id"` + PsCountryId valueTypes.Integer `json:"ps_country_id"` + PsCreateUserId valueTypes.Integer `json:"ps_create_user_id"` PsCurrentTimeZone valueTypes.String `json:"ps_current_time_zone"` PsDirectOrgList []struct { - OrgID valueTypes.Integer `json:"org_id"` + OrgId valueTypes.Integer `json:"org_id"` OrgIndexCode valueTypes.String `json:"org_index_code"` OrgName valueTypes.String `json:"org_name"` } `json:"ps_direct_org_list"` PsHolder valueTypes.String `json:"ps_holder"` - PsID valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` PsInstalledPower valueTypes.Float `json:"ps_installed_power" PointUnit:"W"` PsKey valueTypes.PsKey `json:"ps_key"` PsLocation valueTypes.String `json:"ps_location"` @@ -105,22 +113,22 @@ type ResultData struct { Installer valueTypes.String `json:"installer"` InstallerEmail valueTypes.String `json:"installer_email"` InstallerPhone valueTypes.String `json:"installer_phone"` - OrgID valueTypes.Integer `json:"org_id"` + OrgId valueTypes.Integer `json:"org_id"` OrgIndexCode valueTypes.String `json:"org_index_code"` OrgName valueTypes.String `json:"org_name"` PsDealerOrgCode valueTypes.String `json:"ps_dealer_org_code"` - UpOrgID valueTypes.Integer `json:"up_org_id"` + UpOrgId valueTypes.Integer `json:"up_org_id"` } `json:"ps_org_info"` PsPrice valueTypes.Float `json:"ps_price" PointUnitFrom:"ParamIncomeUnitName"` PsPriceKwh valueTypes.Float `json:"ps_price_kwh" PointUnitFrom:"ParamIncomeUnitName"` PsType valueTypes.Integer `json:"ps_type"` PsTypeDesc valueTypes.String `json:"ps_type_desc"` PsTypeName valueTypes.String `json:"ps_type_name"` - PsUserID valueTypes.Integer `json:"ps_user_id"` + PsUserId valueTypes.Integer `json:"ps_user_id"` RecordCreateTime valueTypes.DateTime `json:"recore_create_time" PointId:"record_create_time"` SafeStartDate valueTypes.DateTime `json:"safe_start_date"` SelectedOrgList []struct { - OrgID valueTypes.Integer `json:"org_id"` + OrgId valueTypes.Integer `json:"org_id"` OrgIndexCode valueTypes.String `json:"org_index_code"` OrgName valueTypes.String `json:"org_name"` } `json:"selectedOrgList" PointId:"selected_org_list"` @@ -133,14 +141,14 @@ type ResultData struct { SnDetailList []struct { CommunicateDeviceType valueTypes.Integer `json:"communicate_device_type"` CommunicateDeviceTypeName valueTypes.String `json:"communicate_device_type_name"` - ID valueTypes.Integer `json:"id"` + Id valueTypes.Integer `json:"id"` IsEnable valueTypes.Bool `json:"is_enable"` Sn valueTypes.String `json:"sn" PointName:"Serial Number"` } `json:"sn_detail_list"` SummerTimeState valueTypes.Bool `json:"summer_time_state"` SummerTimeZone valueTypes.String `json:"summer_time_zone"` - SummerTimeZoneID valueTypes.Integer `json:"summer_time_zone_id"` - TimeZoneID valueTypes.Integer `json:"time_zone_id"` + SummerTimeZoneId valueTypes.Integer `json:"summer_time_zone_id"` + TimeZoneId valueTypes.Integer `json:"time_zone_id"` Timezone valueTypes.String `json:"timezone"` UserAccount valueTypes.String `json:"user_account"` UserCapacityStatus valueTypes.Integer `json:"user_capacity_status"` diff --git a/iSolarCloud/AppService/getPowerStationInfo/data.go b/iSolarCloud/AppService/getPowerStationInfo/data.go index a2d9bc059..dfc89bef3 100644 --- a/iSolarCloud/AppService/getPowerStationInfo/data.go +++ b/iSolarCloud/AppService/getPowerStationInfo/data.go @@ -12,7 +12,7 @@ const Url = "/v1/powerStationService/getPowerStationInfo" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { @@ -29,7 +29,7 @@ type ResultData struct { RemindType interface{} `json:"remindType" PointId:"remind_type"` PowerStationMap struct { - AreaID interface{} `json:"area_id"` + AreaId interface{} `json:"area_id"` ConnectType valueTypes.Integer `json:"connect_type"` County interface{} `json:"county"` CountyCode interface{} `json:"county_code"` @@ -51,10 +51,10 @@ type ResultData struct { Prov interface{} `json:"prov"` ProvCode interface{} `json:"prov_code"` PsBuildDate valueTypes.DateTime `json:"ps_build_date"` - PsCountryID valueTypes.Integer `json:"ps_country_id"` + PsCountryId valueTypes.Integer `json:"ps_country_id"` PsDesc interface{} `json:"ps_desc"` PsHolder valueTypes.String `json:"ps_holder"` - PsID valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` PsLocation valueTypes.String `json:"ps_location"` PsName valueTypes.String `json:"ps_name"` PsType valueTypes.Integer `json:"ps_type"` @@ -62,7 +62,7 @@ type ResultData struct { ReportType interface{} `json:"report_type"` ShippingAddress valueTypes.String `json:"shipping_address"` ShippingZipCode valueTypes.String `json:"shipping_zip_code"` - TimeZoneID valueTypes.Integer `json:"time_zone_id"` + TimeZoneId valueTypes.Integer `json:"time_zone_id"` ValidFlag valueTypes.Integer `json:"valid_flag"` Village interface{} `json:"village"` VillageCode interface{} `json:"village_code"` @@ -76,19 +76,19 @@ type ResultData struct { InstallerEmail valueTypes.String `json:"installer_email"` InstallerPhone valueTypes.String `json:"installer_phone"` OrgURL interface{} `json:"org_url"` - UpOrgID valueTypes.Integer `json:"up_org_id"` + UpOrgId valueTypes.Integer `json:"up_org_id"` } `json:"installProviderInfo" PointId:"install_provider_info"` PowerChargeDataMap struct { CodeType valueTypes.Integer `json:"code_type"` DefaultCharge valueTypes.Float `json:"default_charge"` - ElectricChargeID valueTypes.Integer `json:"electric_charge_id"` + ElectricChargeId valueTypes.Integer `json:"electric_charge_id"` EndTime valueTypes.DateTime `json:"end_time"` IntervalTimeCharge interface{} `json:"interval_time_charge"` ParamIncomeUnitName valueTypes.String `json:"param_income_unit_name"` StartTime valueTypes.DateTime `json:"start_time"` } `json:"powerChargeDataMap" PointId:"power_charge_data_map"` SysTimeZones []struct { - ID valueTypes.Integer `json:"id"` + Id valueTypes.Integer `json:"id"` TimezoneName valueTypes.String `json:"timezone_name"` TimezoneUtc valueTypes.String `json:"timezone_utc"` } `json:"sysTimeZones" PointId:"sys_time_zones"` diff --git a/iSolarCloud/AppService/getPowerStatistics/data.go b/iSolarCloud/AppService/getPowerStatistics/data.go index 897c116b0..019e6994d 100644 --- a/iSolarCloud/AppService/getPowerStatistics/data.go +++ b/iSolarCloud/AppService/getPowerStatistics/data.go @@ -12,7 +12,7 @@ const Url = "/v1/powerStationService/getPowerStatistics" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { @@ -25,7 +25,7 @@ func (rd RequestData) Help() string { } type ResultData struct { - City interface{} `json:"city"` + City valueTypes.String `json:"city"` PsName valueTypes.String `json:"ps_name"` PsShortName valueTypes.String `json:"ps_short_name"` Status1 valueTypes.Integer `json:"status1"` diff --git a/iSolarCloud/AppService/getPsDetail/data.go b/iSolarCloud/AppService/getPsDetail/data.go index b29750e40..0d1d8b54e 100644 --- a/iSolarCloud/AppService/getPsDetail/data.go +++ b/iSolarCloud/AppService/getPsDetail/data.go @@ -12,7 +12,7 @@ const Url = "/v1/powerStationService/getPsDetail" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { @@ -27,8 +27,8 @@ func (rd RequestData) Help() string { type ResultData struct { ActualEnergy []valueTypes.Float `json:"actual_energy" PointId:"actual_energy" PointName:"Actual Energy" PointUnitFrom:"ActualEnergyUnit"` ActualEnergyUnit valueTypes.String `json:"actual_energy_unit" PointId:"actual_energy_unit" PointIgnore:"true"` - AlarmCount valueTypes.Integer `json:"alarm_count"` - AreaID interface{} `json:"area_id"` + AlarmCount valueTypes.Count `json:"alarm_count"` + AreaId interface{} `json:"area_id"` AreaType valueTypes.Integer `json:"area_type"` BuildDate valueTypes.DateTime `json:"build_date"` Co2Reduce valueTypes.UnitValue `json:"co2_reduce"` @@ -47,7 +47,7 @@ type ResultData struct { DiagramURL valueTypes.String `json:"diagram_url"` EnergyScheme interface{} `json:"energy_scheme"` ExpectInstallDate valueTypes.DateTime `json:"expect_install_date"` - FaultCount valueTypes.Integer `json:"fault_count"` + FaultCount valueTypes.Count `json:"fault_count"` FaultSendType string `json:"fault_send_type"` GcjLatitude valueTypes.Float `json:"gcj_latitude"` GcjLongitude valueTypes.Float `json:"gcj_longitude"` @@ -159,7 +159,7 @@ type ResultData struct { PowderReduceTotal valueTypes.UnitValue `json:"powder_reduce_total" PointId:"powder_reduce_total" PointUpdateFreq:"UpdateFreqTotal"` PowerChargeSetted valueTypes.Bool `json:"power_charge_setted" PointId:"power_charge_set" PointUpdateFreq:"UpdateFreqTotal"` Producer string `json:"producer"` - PsCountryID valueTypes.Integer `json:"ps_country_id"` + PsCountryId valueTypes.Integer `json:"ps_country_id"` PsFaultStatus valueTypes.Integer `json:"ps_fault_status"` PsHealthStatus valueTypes.Integer `json:"ps_health_status"` PsHolder valueTypes.String `json:"ps_holder"` @@ -180,7 +180,7 @@ type ResultData struct { So2Reduce valueTypes.UnitValue `json:"so2_reduce"` So2ReduceTotal valueTypes.UnitValue `json:"so2_reduce_total" PointId:"so2_reduce_total" PointUpdateFreq:"UpdateFreqTotal"` SysScheme valueTypes.Integer `json:"sys_scheme"` - TimeZoneID valueTypes.Integer `json:"time_zone_id"` + TimeZoneId valueTypes.Integer `json:"time_zone_id"` Timezone valueTypes.String `json:"timezone"` TodayEnergy valueTypes.UnitValue `json:"today_energy" PointId:"today_energy" PointUpdateFreq:"UpdateFreqDay"` TodayEnergyVirgin valueTypes.UnitValue `json:"today_energy_virgin" PointIgnore:"true"` @@ -193,7 +193,7 @@ type ResultData struct { TreeReduceTotal valueTypes.UnitValue `json:"tree_reduce_total" PointId:"tree_reduce_total" PointUpdateFreq:"UpdateFreqTotal"` TuvLevel string `json:"tuv_level"` ValidFlag valueTypes.Bool `json:"valid_flag"` - WaitAssignOrderCount valueTypes.Integer `json:"wait_assign_order_count"` + WaitAssignOrderCount valueTypes.Count `json:"wait_assign_order_count"` WaterReduce valueTypes.UnitValue `json:"water_reduce"` WaterReduceTotal valueTypes.UnitValue `json:"water_reduce_total" PointId:"water_reduce_total" PointUpdateFreq:"UpdateFreqTotal"` WgsLatitude valueTypes.Float `json:"wgs_latitude"` @@ -210,8 +210,8 @@ type ResultData struct { SweepCapacity valueTypes.Float `json:"sweep_capacity"` } `json:"robot_num_sweep_capacity"` Images []struct { - FileID valueTypes.Integer `json:"file_id"` - ID valueTypes.Integer `json:"id"` + FileId valueTypes.Integer `json:"file_id"` + Id valueTypes.Integer `json:"id"` PicLanguage valueTypes.Integer `json:"pic_language"` PicType valueTypes.Integer `json:"pic_type"` PictureName valueTypes.String `json:"picture_name"` diff --git a/iSolarCloud/AppService/getPsDetailWithPsType/data.go b/iSolarCloud/AppService/getPsDetailWithPsType/data.go index 8a87be475..3b8c77c11 100644 --- a/iSolarCloud/AppService/getPsDetailWithPsType/data.go +++ b/iSolarCloud/AppService/getPsDetailWithPsType/data.go @@ -13,7 +13,7 @@ const Url = "/v1/powerStationService/getPsDetailWithPsType" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { @@ -75,7 +75,7 @@ type ResultData struct { PowerChargeSetted valueTypes.Bool `json:"power_charge_setted" PointId:"power_charge_set" PointUpdateFreq:"UpdateFreqBoot"` PowerGridPowerMap valueTypes.UnitValue `json:"power_grid_power_map" PointId:"power_grid_power_map" PointUpdateFreq:"UpdateFreq5Mins"` PowerGridPowerMapVirgin valueTypes.UnitValue `json:"power_grid_power_map_virgin" PointIgnore:"true"` - PsCountryID valueTypes.Integer `json:"ps_country_id" PointId:"ps_country_id" PointUpdateFreq:"UpdateFreqBoot"` + PsCountryId valueTypes.Integer `json:"ps_country_id" PointId:"ps_country_id" PointUpdateFreq:"UpdateFreqBoot"` PsDeviceType valueTypes.Integer `json:"ps_device_type" PointId:"ps_device_type" PointUpdateFreq:"UpdateFreqBoot"` PsFaultStatus valueTypes.Integer `json:"ps_fault_status" PointId:"ps_fault_status" PointUpdateFreq:"UpdateFreqInstant"` PsHealthStatus valueTypes.Integer `json:"ps_health_status" PointId:"ps_health_status" PointUpdateFreq:"UpdateFreqInstant"` diff --git a/iSolarCloud/AppService/getPsHealthState/data.go b/iSolarCloud/AppService/getPsHealthState/data.go index fd87ea6c0..c0bc43eb2 100644 --- a/iSolarCloud/AppService/getPsHealthState/data.go +++ b/iSolarCloud/AppService/getPsHealthState/data.go @@ -12,7 +12,7 @@ const Url = "/v1/powerStationService/getPsHealthState" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { diff --git a/iSolarCloud/AppService/getPsList/data.go b/iSolarCloud/AppService/getPsList/data.go index 601eb6ff3..dd94d14a1 100644 --- a/iSolarCloud/AppService/getPsList/data.go +++ b/iSolarCloud/AppService/getPsList/data.go @@ -26,10 +26,10 @@ func (rd RequestData) Help() string { type ResultData struct { PageList []struct { - AlarmCount valueTypes.Integer `json:"alarm_count" PointId:"alarm_count" PointUpdateFreq:"UpdateFreqBoot"` - AlarmDevCount valueTypes.Integer `json:"alarm_dev_count" PointId:"alarm_dev_count" PointUpdateFreq:"UpdateFreqBoot"` - AreaID interface{} `json:"area_id" PointId:"area_id"` - AreaType interface{} `json:"area_type" PointId:"area_type"` + AlarmCount valueTypes.Count `json:"alarm_count" PointId:"alarm_count" PointUpdateFreq:"UpdateFreqBoot"` + AlarmDevCount valueTypes.Count `json:"alarm_dev_count" PointId:"alarm_dev_count" PointUpdateFreq:"UpdateFreqBoot"` + AreaId interface{} `json:"area_id" PointId:"area_id"` + AreaType valueTypes.Integer `json:"area_type" PointId:"area_type"` ArrearsStatus valueTypes.Integer `json:"arrears_status" PointId:"arrears_status"` BuildDate valueTypes.DateTime `json:"build_date" PointId:"build_date" PointUpdateFreq:"UpdateFreqBoot"` BuildStatus valueTypes.Integer `json:"build_status" PointId:"build_status" PointUpdateFreq:"UpdateFreqBoot"` @@ -48,28 +48,28 @@ type ResultData struct { EsTotalDischargeEnergy valueTypes.UnitValue `json:"es_total_disenergy" PointId:"p83095" PointName:"ES Total Discharge Energy" PointUpdateFreq:"UpdateFreqTotal"` EsTotalEnergy valueTypes.UnitValue `json:"es_total_energy" PointId:"p83127" PointName:"ES Total Energy" PointUpdateFreq:"UpdateFreqTotal"` ExpectInstallDate valueTypes.DateTime `json:"expect_install_date" PointId:"expect_install_date"` - FaultAlarmOfflineDevCount valueTypes.Integer `json:"fault_alarm_offline_dev_count" PointId:"fault_alarm_offline_dev_count"` - FaultCount valueTypes.Integer `json:"fault_count" PointId:"fault_count"` - FaultDevCount valueTypes.Integer `json:"fault_dev_count" PointId:"fault_dev_count"` + FaultAlarmOfflineDevCount valueTypes.Count `json:"fault_alarm_offline_dev_count" PointId:"fault_alarm_offline_dev_count"` + FaultCount valueTypes.Count `json:"fault_count" PointId:"fault_count"` + FaultDevCount valueTypes.Count `json:"fault_dev_count" PointId:"fault_dev_count"` GcjLatitude valueTypes.Float `json:"gcj_latitude" PointId:"gcj_latitude"` GcjLongitude valueTypes.Float `json:"gcj_longitude" PointId:"gcj_longitude"` GprsLatitude valueTypes.Float `json:"gprs_latitude" PointId:"gprs_latitude"` GprsLongitude valueTypes.Float `json:"gprs_longitude" PointId:"gprs_longitude"` Images []struct { - FileID valueTypes.Integer `json:"file_id"` - ID valueTypes.Integer `json:"id"` + FileId valueTypes.Integer `json:"file_id"` + Id valueTypes.Integer `json:"id"` PicLanguage valueTypes.Integer `json:"pic_language"` PicType valueTypes.Integer `json:"pic_type"` PictureName valueTypes.String `json:"picture_name"` PictureURL valueTypes.String `json:"picture_url"` - PsID valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` PsUnitUUID interface{} `json:"ps_unit_uuid"` } `json:"images" PointName:"Images"` InstallDate valueTypes.DateTime `json:"install_date" PointId:"install_date"` InstalledPowerMap valueTypes.UnitValue `json:"installed_power_map" PointId:"installed_power_map"` InstalledPowerVirgin valueTypes.Float `json:"installed_power_virgin" PointIgnore:"true"` - InstallerAlarmCount valueTypes.Integer `json:"installer_alarm_count" PointId:"installer_alarm_count"` - InstallerFaultCount valueTypes.Integer `json:"installer_fault_count" PointId:"installer_fault_count"` + InstallerAlarmCount valueTypes.Count `json:"installer_alarm_count" PointId:"installer_alarm_count"` + InstallerFaultCount valueTypes.Count `json:"installer_fault_count" PointId:"installer_fault_count"` InstallerPsFaultStatus valueTypes.Integer `json:"installer_ps_fault_status" PointId:"installer_ps_fault_status"` IsBankPs valueTypes.Bool `json:"is_bank_ps" PointId:"is_bank_ps"` IsTuv valueTypes.Bool `json:"is_tuv" PointId:"is_tuv"` @@ -81,11 +81,11 @@ type ResultData struct { MapLongitude valueTypes.Float `json:"map_longitude" PointId:"map_longitude"` MlpeFlag valueTypes.Integer `json:"mlpe_flag" PointId:"mlpe_flag"` Nmi valueTypes.String `json:"nmi" PointId:"nmi"` - OfflineDevCount valueTypes.Integer `json:"offline_dev_count" PointId:"offline_dev_count"` + OfflineDevCount valueTypes.Count `json:"offline_dev_count" PointId:"offline_dev_count"` OperateYear interface{} `json:"operate_year" PointId:"operate_year"` OperationBusName valueTypes.String `json:"operation_bus_name" PointId:"operation_bus_name"` - OwnerAlarmCount valueTypes.Integer `json:"owner_alarm_count" PointId:"owner_alarm_count"` - OwnerFaultCount valueTypes.Integer `json:"owner_fault_count" PointId:"owner_fault_count"` + OwnerAlarmCount valueTypes.Count `json:"owner_alarm_count" PointId:"owner_alarm_count"` + OwnerFaultCount valueTypes.Count `json:"owner_fault_count" PointId:"owner_fault_count"` OwnerPsFaultStatus valueTypes.Integer `json:"owner_ps_fault_status" PointId:"owner_ps_fault_status"` P83022y valueTypes.String `json:"p83022y" PointId:"p83022" PointUpdateFreq:"UpdateFreq5Mins"` P83046 valueTypes.Float `json:"p83046" PointId:"p83046" PointUpdateFreq:"UpdateFreq5Mins"` @@ -116,11 +116,11 @@ type ResultData struct { ParamWater valueTypes.Float `json:"param_water" PointId:"param_water"` PrScale string `json:"pr_scale" PointId:"pr_scale"` Producer interface{} `json:"producer" PointId:"producer"` - PsCountryID valueTypes.Integer `json:"ps_country_id" PointId:"ps_country_id"` + PsCountryId valueTypes.Integer `json:"ps_country_id" PointId:"ps_country_id"` PsFaultStatus valueTypes.Integer `json:"ps_fault_status" PointId:"ps_fault_status"` PsHealthStatus valueTypes.Integer `json:"ps_health_status" PointId:"ps_health_status"` PsHolder valueTypes.String `json:"ps_holder" PointId:"ps_holder"` - PsId valueTypes.Integer `json:"ps_id" PointId:"ps_id"` + PsId valueTypes.PsId `json:"ps_id" PointId:"ps_id"` PsIsNotInit valueTypes.Bool `json:"ps_is_not_init" PointId:"ps_is_not_init"` PsName valueTypes.String `json:"ps_name" PointId:"ps_name"` PsShortName valueTypes.String `json:"ps_short_name" PointId:"ps_short_name"` @@ -150,7 +150,7 @@ type ResultData struct { WgsLongitude valueTypes.Float `json:"wgs_longitude" PointId:"wgs_longitude"` ZipCode valueTypes.String `json:"zip_code" PointId:"zip_code"` } `json:"pageList" PointNameFromChild:"PsId"` - RowCount valueTypes.Integer `json:"rowCount" PointIgnore:"true"` + RowCount valueTypes.Count `json:"rowCount" PointIgnore:"true"` } func (e *ResultData) IsValid() error { @@ -180,7 +180,7 @@ type Device struct { PsFaultStatus valueTypes.Integer PsHealthStatus valueTypes.Integer PsHolder valueTypes.String - PsID valueTypes.Integer + PsId valueTypes.PsId PsName valueTypes.String PsShortName valueTypes.String PsStatus valueTypes.Integer @@ -195,7 +195,7 @@ func (e *ResultData) GetPsDevices() Devices { PsFaultStatus: d.PsFaultStatus, PsHealthStatus: d.PsHealthStatus, PsHolder: d.PsHolder, - PsID: d.PsId, + PsId: d.PsId, PsName: d.PsName, PsShortName: d.PsShortName, PsStatus: d.PsStatus, @@ -205,8 +205,8 @@ func (e *ResultData) GetPsDevices() Devices { return ret } -func (e *ResultData) GetPsIds() []valueTypes.Integer { - var ret []valueTypes.Integer +func (e *ResultData) GetPsIds() []valueTypes.PsId { + var ret []valueTypes.PsId for range Only.Once { i := len(e.PageList) if i == 0 { @@ -253,6 +253,6 @@ func (e *ResultData) GetPsSerial() []string { return ret } -func (e *EndPoint) GetPsIds() []valueTypes.Integer { +func (e *EndPoint) GetPsIds() []valueTypes.PsId { return e.Response.ResultData.GetPsIds() } diff --git a/iSolarCloud/AppService/getPsListByName/data.go b/iSolarCloud/AppService/getPsListByName/data.go index 51db1140c..a98cd6c21 100644 --- a/iSolarCloud/AppService/getPsListByName/data.go +++ b/iSolarCloud/AppService/getPsListByName/data.go @@ -4,8 +4,8 @@ import ( "GoSungrow/iSolarCloud/api" "GoSungrow/iSolarCloud/api/apiReflect" "GoSungrow/iSolarCloud/api/valueTypes" - "github.com/MickMake/GoUnify/Only" "fmt" + "github.com/MickMake/GoUnify/Only" ) const Url = "/v1/powerStationService/getPsListByName" @@ -25,12 +25,12 @@ func (rd RequestData) Help() string { } type ResultData []struct { - PsID valueTypes.Integer `json:"ps_id"` - PsName valueTypes.String `json:"ps_name"` - PsShortName valueTypes.String `json:"ps_short_name"` - PsTimezone valueTypes.String `json:"ps_timezone"` - PsTimezoneID valueTypes.Integer `json:"ps_timezone_id"` - ShareType string `json:"share_type"` + PsId valueTypes.PsId `json:"ps_id"` + PsName valueTypes.String `json:"ps_name"` + PsShortName valueTypes.String `json:"ps_short_name"` + PsTimezone valueTypes.String `json:"ps_timezone"` + PsTimezoneId valueTypes.Integer `json:"ps_timezone_id"` + ShareType valueTypes.Integer `json:"share_type"` } func (e *ResultData) IsValid() error { @@ -44,30 +44,14 @@ func (e *ResultData) IsValid() error { return err } -//type DecodeResultData ResultData -// -//func (e *ResultData) UnmarshalJSON(data []byte) error { -// var err error -// -// for range Only.Once { -// if len(data) == 0 { -// break -// } -// var pd DecodeResultData -// -// // Store ResultData -// _ = json.Unmarshal(data, &pd) -// e.Dummy = pd.Dummy -// } -// -// return err -//} - func (e *EndPoint) GetData() api.DataMap { entries := api.NewDataMap() for range Only.Once { - entries.StructToPoints(e.Response.ResultData, apiReflect.GetName("", *e), "system", valueTypes.NewDateTime("")) + pkg := apiReflect.GetName("", *e) + dt := valueTypes.NewDateTime(valueTypes.Now) + // name := pkg + "." + e.Request.PsId.String() + entries.StructToPoints(e.Response.ResultData, pkg, "system", dt) } return entries diff --git a/iSolarCloud/AppService/getPsListStaticData/data.go b/iSolarCloud/AppService/getPsListStaticData/data.go index a0e407e5e..3062e6d27 100644 --- a/iSolarCloud/AppService/getPsListStaticData/data.go +++ b/iSolarCloud/AppService/getPsListStaticData/data.go @@ -4,8 +4,8 @@ import ( "GoSungrow/iSolarCloud/api" "GoSungrow/iSolarCloud/api/apiReflect" "GoSungrow/iSolarCloud/api/valueTypes" - "github.com/MickMake/GoUnify/Only" "fmt" + "github.com/MickMake/GoUnify/Only" ) const Url = "/v1/powerStationService/getPsListStaticData" @@ -26,27 +26,27 @@ func (rd RequestData) Help() string { type ResultData struct { PageList []struct { - AreaID interface{} `json:"area_id"` - DesignCapacity valueTypes.Float `json:"design_capacity"` - GprsLatitude valueTypes.Float `json:"gprs_latitude"` - GprsLongitude valueTypes.Float `json:"gprs_longitude"` - InstallDate valueTypes.DateTime `json:"install_date"` - InstallerPsFaultStatus valueTypes.Integer `json:"installer_ps_fault_status"` - Latitude valueTypes.Float `json:"latitude"` - Location valueTypes.String `json:"location"` - Longitude valueTypes.Float `json:"longitude"` - MapLatitude valueTypes.Float `json:"map_latitude"` - MapLongitude valueTypes.Float `json:"map_longitude"` - OwnerPsFaultStatus valueTypes.Integer `json:"owner_ps_fault_status"` - PsFaultStatus valueTypes.Integer `json:"ps_fault_status"` - PsID valueTypes.Integer `json:"ps_id"` - PsName valueTypes.String `json:"ps_name"` - PsShortName valueTypes.String `json:"ps_short_name"` - PsStatus valueTypes.Integer `json:"ps_status"` - PsType valueTypes.Integer `json:"ps_type"` - ValidFlag valueTypes.Integer `json:"valid_flag"` - WaitAssignOrderCount valueTypes.Integer `json:"wait_assign_order_count"` - } `json:"pageList"` + AreaId interface{} `json:"area_id"` + DesignCapacity valueTypes.Float `json:"design_capacity" PointUnit:"W"` + GprsLatitude valueTypes.Float `json:"gprs_latitude"` + GprsLongitude valueTypes.Float `json:"gprs_longitude"` + InstallDate valueTypes.DateTime `json:"install_date"` + InstallerPsFaultStatus valueTypes.Integer `json:"installer_ps_fault_status"` + Latitude valueTypes.Float `json:"latitude"` + Location valueTypes.String `json:"location"` + Longitude valueTypes.Float `json:"longitude"` + MapLatitude valueTypes.Float `json:"map_latitude"` + MapLongitude valueTypes.Float `json:"map_longitude"` + OwnerPsFaultStatus valueTypes.Integer `json:"owner_ps_fault_status"` + PsFaultStatus valueTypes.Integer `json:"ps_fault_status"` + PsId valueTypes.PsId `json:"ps_id"` + PsName valueTypes.String `json:"ps_name"` + PsShortName valueTypes.String `json:"ps_short_name"` + PsStatus valueTypes.Integer `json:"ps_status"` + PsType valueTypes.Integer `json:"ps_type"` + ValidFlag valueTypes.Bool `json:"valid_flag"` + WaitAssignOrderCount valueTypes.Integer `json:"wait_assign_order_count"` + } `json:"pageList" PointId:"page_list" PointNameFromChild:"PsId" PointNameFromAppend:"false"` RowCount valueTypes.Integer `json:"rowCount"` } @@ -61,30 +61,14 @@ func (e *ResultData) IsValid() error { return err } -//type DecodeResultData ResultData -// -//func (e *ResultData) UnmarshalJSON(data []byte) error { -// var err error -// -// for range Only.Once { -// if len(data) == 0 { -// break -// } -// var pd DecodeResultData -// -// // Store ResultData -// _ = json.Unmarshal(data, &pd) -// e.Dummy = pd.Dummy -// } -// -// return err -//} - func (e *EndPoint) GetData() api.DataMap { entries := api.NewDataMap() for range Only.Once { - entries.StructToPoints(e.Response.ResultData, apiReflect.GetName("", *e), "system", valueTypes.NewDateTime("")) + pkg := apiReflect.GetName("", *e) + dt := valueTypes.NewDateTime(valueTypes.Now) + // name := pkg + "." + e.Request.PsId.String() + entries.StructToPoints(e.Response.ResultData, pkg, "system", dt) } return entries diff --git a/iSolarCloud/AppService/getPsReport/data.go b/iSolarCloud/AppService/getPsReport/data.go index 195f38f76..d6aee1833 100644 --- a/iSolarCloud/AppService/getPsReport/data.go +++ b/iSolarCloud/AppService/getPsReport/data.go @@ -4,16 +4,16 @@ import ( "GoSungrow/iSolarCloud/api" "GoSungrow/iSolarCloud/api/apiReflect" "GoSungrow/iSolarCloud/api/valueTypes" - "github.com/MickMake/GoUnify/Only" "fmt" + "github.com/MickMake/GoUnify/Only" ) const Url = "/v1/reportService/getPsReport" const Disabled = false type RequestData struct { - ReportType string `json:"report_type" required:"true"` - DateID string `json:"date_id" required:"true"` + ReportType valueTypes.Integer `json:"report_type" required:"true"` + DateId valueTypes.DateTime `json:"date_id" required:"true"` } func (rd RequestData) IsValid() error { @@ -21,61 +21,57 @@ func (rd RequestData) IsValid() error { } func (rd RequestData) Help() string { - ret := fmt.Sprintf("") + ret := fmt.Sprintf("report_type: One of 1, 2, 5") ret += api.HelpDataType() return ret } type ResultData struct { - PsDateRangeTotalData struct { - Co2Reduce valueTypes.Float `json:"co2_reduce"` - Co2ReduceMap valueTypes.UnitValue `json:"co2_reduce_map"` - Co2ReduceOriginalUnit valueTypes.String `json:"co2_reduce_original_unit"` - PowerQuantityTotal valueTypes.Float `json:"power_quantity_total"` - PowerQuantityTotalMap valueTypes.UnitValue `json:"power_quantity_total_map"` - PowerQuantityTotalOriginalUnit valueTypes.String `json:"power_quantity_total_original_unit"` - ProfitList ProfitList `json:"profit_list"` - TotalProfit valueTypes.Float `json:"total_profit"` - } `json:"ps_date_range_total_data"` - PsTotalData struct { - Co2Reduce valueTypes.Float `json:"co2_reduce"` - Co2ReduceMap valueTypes.UnitValue `json:"co2_reduce_map"` - Co2ReduceOriginalUnit valueTypes.String `json:"co2_reduce_original_unit"` - MinDateID valueTypes.DateTime `json:"min_date_id"` - PowerQuantityTotal valueTypes.Float `json:"power_quantity_total"` - PowerQuantityTotalMap valueTypes.UnitValue `json:"power_quantity_total_map"` - PowerQuantityTotalOriginalUnit valueTypes.String `json:"power_quantity_total_original_unit"` - ProfitList ProfitList `json:"profit_list"` - TotalProfit valueTypes.Float `json:"total_profit"` - } `json:"ps_total_data"` - ReportListData struct { - Co2ReduceUnit valueTypes.String `json:"co2_reduce_unit"` + PsDateRangeTotalData TotalData `json:"ps_date_range_total_data"` + PsTotalData TotalData `json:"ps_total_data"` + ReportListData struct { PageList []struct { - Co2Reduce valueTypes.Float `json:"co2_reduce"` - IncomeUnitName valueTypes.String `json:"income_unit_name"` - PowerQuantityTotal valueTypes.Float `json:"power_quantity_total"` - PsID valueTypes.Integer`json:"ps_id"` - PsInstalledPower valueTypes.Float `json:"ps_installed_power"` - PsName valueTypes.String `json:"ps_name"` - PsTotalCo2Reduce valueTypes.Float `json:"ps_total_co2_reduce"` - PsTotalPower valueTypes.Float `json:"ps_total_power"` - PsType valueTypes.Integer`json:"ps_type"` - ShareType string `json:"share_type"` - ProfitList ProfitList `json:"profit_list"` - TotalProfit valueTypes.Float `json:"total_profit"` - } `json:"pageList"` - PowerQuantityTotalUnit valueTypes.String `json:"power_quantity_total_unit"` - PsInstalledPowerUnit valueTypes.String `json:"ps_installed_power_unit"` - PsTotalCo2ReduceUnit valueTypes.String `json:"ps_total_co2_reduce_unit"` - PsTotalPowerUnit valueTypes.String `json:"ps_total_power_unit"` - RowCount valueTypes.Integer `json:"rowCount"` - } `json:"report_list_data"` + PsId valueTypes.PsId `json:"ps_id"` + PsName valueTypes.String `json:"ps_name"` + PsType valueTypes.Integer `json:"ps_type"` + ShareType valueTypes.String `json:"share_type"` + Co2Reduce valueTypes.Float `json:"co2_reduce" PointUnitFromParent:"PsTotalCo2ReduceUnit"` + PowerQuantityTotal valueTypes.Float `json:"power_quantity_total" PointUnitFromParent:"PowerQuantityTotalUnit"` + PsInstalledPower valueTypes.Float `json:"ps_installed_power" PointUnitFromParent:"PsInstalledPowerUnit"` + PsTotalCo2Reduce valueTypes.Float `json:"ps_total_co2_reduce" PointUnitFromParent:"PsTotalCo2ReduceUnit"` + PsTotalPower valueTypes.Float `json:"ps_total_power" PointUnitFromParent:"PsTotalPowerUnit"` + TotalProfit valueTypes.Float `json:"total_profit" PointUnitFrom:"IncomeUnitName"` + IncomeUnitName valueTypes.String `json:"income_unit_name" PointIgnore:"true"` + ProfitList ProfitList `json:"profit_list"` + } `json:"pageList" PointId:"page_list" PointNameFromChild:"PsId" PointNameFromAppend:"false"` + Co2ReduceUnit valueTypes.String `json:"co2_reduce_unit" PointIgnore:"true"` + PowerQuantityTotalUnit valueTypes.String `json:"power_quantity_total_unit" PointIgnore:"true"` + PsInstalledPowerUnit valueTypes.String `json:"ps_installed_power_unit" PointIgnore:"true"` + PsTotalCo2ReduceUnit valueTypes.String `json:"ps_total_co2_reduce_unit" PointIgnore:"true"` + PsTotalPowerUnit valueTypes.String `json:"ps_total_power_unit" PointIgnore:"true"` + RowCount valueTypes.Integer `json:"rowCount" PointId:"row_count"` + } `json:"report_list_data" PointId:"total_by_ps" PointNameFromAppend:"false"` +} + +type TotalData struct { + MinDateId valueTypes.DateTime `json:"min_date_id"` + + Co2Reduce valueTypes.Float `json:"co2_reduce" PointUnitFrom:"Co2ReduceOriginalUnit"` + Co2ReduceMap valueTypes.UnitValue `json:"co2_reduce_map"` + Co2ReduceOriginalUnit valueTypes.String `json:"co2_reduce_original_unit" PointIgnore:"true"` + + PowerQuantityTotal valueTypes.Float `json:"power_quantity_total" PointUnitFrom:"PowerQuantityTotalOriginalUnit"` + PowerQuantityTotalMap valueTypes.UnitValue `json:"power_quantity_total_map"` + PowerQuantityTotalOriginalUnit valueTypes.String `json:"power_quantity_total_original_unit" PointIgnore:"true"` + + ProfitList ProfitList `json:"profit_list"` + TotalProfit valueTypes.Float `json:"total_profit" PointUnitFrom:"IncomeUnitName"` } type ProfitList []struct { - IncomeUnitID valueTypes.Integer `json:"income_unit_id"` - IncomeUnitName valueTypes.String `json:"income_unit_name"` - TotalProfit valueTypes.Float `json:"total_profit"` + IncomeUnitId valueTypes.Integer `json:"income_unit_id"` + IncomeUnitName valueTypes.String `json:"income_unit_name" PointIgnore:"true"` + TotalProfit valueTypes.Float `json:"total_profit" PointUnitFrom:"IncomeUnitName"` } func (e *ResultData) IsValid() error { @@ -89,30 +85,14 @@ func (e *ResultData) IsValid() error { return err } -// type DecodeResultData ResultData -// -// func (e *ResultData) UnmarshalJSON(data []byte) error { -// var err error -// -// for range Only.Once { -// if len(data) == 0 { -// break -// } -// var pd DecodeResultData -// -// // Store ResultData -// _ = json.Unmarshal(data, &pd) -// e.Dummy = pd.Dummy -// } -// -// return err -// } - func (e *EndPoint) GetData() api.DataMap { entries := api.NewDataMap() for range Only.Once { - entries.StructToPoints(e.Response.ResultData, apiReflect.GetName("", *e), "system", valueTypes.NewDateTime("")) + pkg := apiReflect.GetName("", *e) + dt := valueTypes.NewDateTime(valueTypes.Now) + name := pkg + "." + e.Request.DateId.Format(valueTypes.DateTimeLayoutDay) + entries.StructToPoints(e.Response.ResultData, name, e.Request.DateId.String(), dt) } return entries diff --git a/iSolarCloud/AppService/getPsUser/data.go b/iSolarCloud/AppService/getPsUser/data.go index bc7c09fdd..94895e4db 100644 --- a/iSolarCloud/AppService/getPsUser/data.go +++ b/iSolarCloud/AppService/getPsUser/data.go @@ -27,10 +27,10 @@ func (rd RequestData) Help() string { type ResultData struct { BackgroundColor valueTypes.Integer `json:"background_color"` BloodType valueTypes.String `json:"blood_type"` - CountryID valueTypes.Integer `json:"country_id"` + CountryId valueTypes.Integer `json:"country_id"` CountryName valueTypes.String `json:"country_name"` CreateDate valueTypes.DateTime `json:"create_date"` - CreateUserID valueTypes.Integer `json:"create_user_id"` + CreateUserId valueTypes.Integer `json:"create_user_id"` DiseaseHis valueTypes.String `json:"disease_his"` Email valueTypes.String `json:"email"` EnglishName valueTypes.String `json:"english_name"` @@ -46,19 +46,19 @@ type ResultData struct { LackOfInformation valueTypes.Integer `json:"lack_of_information"` Language valueTypes.String `json:"language"` MobileTel valueTypes.String `json:"moble_tel"` - OrgID valueTypes.Integer `json:"org_id"` - PhotoID valueTypes.Integer `json:"photo_id"` + OrgId valueTypes.Integer `json:"org_id"` + PhotoId valueTypes.Integer `json:"photo_id"` PhotoURL valueTypes.String `json:"photo_url"` - RootOrgID valueTypes.Integer `json:"root_org_id"` + RootOrgId valueTypes.Integer `json:"root_org_id"` Sex valueTypes.String `json:"sex"` Stylename valueTypes.String `json:"stylename"` - TimeZoneID valueTypes.Integer `json:"time_zone_id"` + TimeZoneId valueTypes.Integer `json:"time_zone_id"` Timezone valueTypes.String `json:"timezone"` UserAccount valueTypes.String `json:"user_account"` UserAccountModifyCount valueTypes.Integer `json:"user_account_modify_count"` UserAccountModifyRemainTimes valueTypes.Integer `json:"user_account_modify_remain_times"` UserDealerOrgCode valueTypes.String `json:"user_dealer_org_code"` - UserID valueTypes.Integer `json:"user_id"` + UserId valueTypes.Integer `json:"user_id"` UserLanguage valueTypes.String `json:"user_language"` UserLevel valueTypes.Integer `json:"user_level"` UserName valueTypes.String `json:"user_name"` @@ -70,7 +70,7 @@ type ResultData struct { InstallerPhone valueTypes.String `json:"installer_phone"` IsCountryDefaultDealerOrgCode valueTypes.Bool `json:"is_country_default_dealer_org_code"` MobileTel valueTypes.String `json:"moble_tel"` - OrgID valueTypes.Integer `json:"org_id"` + OrgId valueTypes.Integer `json:"org_id"` OrgIndexCode valueTypes.String `json:"org_index_code"` OrgName valueTypes.String `json:"org_name"` UpDealerEmail valueTypes.String `json:"up_dealer_email"` @@ -81,7 +81,7 @@ type ResultData struct { UpDealerOrgInstallerPhone valueTypes.String `json:"up_dealer_org_installer_phone"` UpDealerUserName valueTypes.String `json:"up_dealer_user_name"` UpDealerUserTelNationCode valueTypes.String `json:"up_dealer_user_tel_nation_code"` - UpOrgID valueTypes.Integer `json:"up_org_id"` + UpOrgId valueTypes.Integer `json:"up_org_id"` UpOrgName valueTypes.String `json:"up_org_name"` UserName valueTypes.String `json:"user_name"` UserTelNationCode valueTypes.String `json:"user_tel_nation_code"` diff --git a/iSolarCloud/AppService/getPsWeatherList/data.go b/iSolarCloud/AppService/getPsWeatherList/data.go index 9c6408470..8f0b03c28 100644 --- a/iSolarCloud/AppService/getPsWeatherList/data.go +++ b/iSolarCloud/AppService/getPsWeatherList/data.go @@ -12,7 +12,7 @@ const Url = "/v1/powerStationService/getPsWeatherList" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { @@ -28,7 +28,7 @@ type ResultData struct { WeatherList []struct { Chill valueTypes.Float `json:"chill"` Code valueTypes.Float `json:"code"` - CodeName valueTypes.Float `json:"code_name"` + CodeName valueTypes.String `json:"code_name"` DateTime valueTypes.DateTime `json:"date_time" PointIgnore:"true"` Direction valueTypes.Float `json:"direction"` High valueTypes.Float `json:"high" PointUnit:"F"` @@ -37,7 +37,7 @@ type ResultData struct { Low valueTypes.Float `json:"low" PointUnit:"F"` Lowc valueTypes.Float `json:"lowc" PointUnit:"C"` Pressure valueTypes.Float `json:"pressure" PointUnit:"hPa"` - PsID valueTypes.Float `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` Rising valueTypes.Float `json:"rising"` Speed valueTypes.Float `json:"speed"` Sunrise valueTypes.Time `json:"sunrise"` diff --git a/iSolarCloud/AppService/getRegionalTree/data.go b/iSolarCloud/AppService/getRegionalTree/data.go index 289ce2e19..9b1f6b291 100644 --- a/iSolarCloud/AppService/getRegionalTree/data.go +++ b/iSolarCloud/AppService/getRegionalTree/data.go @@ -28,14 +28,14 @@ func (rd RequestData) Help() string { type ResultData struct { ResultList []struct { Checked valueTypes.Bool `json:"checked"` - ID valueTypes.String `json:"id"` + Id valueTypes.String `json:"id"` IsFirstOrg valueTypes.Bool `json:"isFirstOrg"` IsParent valueTypes.Bool `json:"isParent"` Name valueTypes.String `json:"name"` Open valueTypes.Bool `json:"open"` - OrgID valueTypes.Integer `json:"org_id"` - PID valueTypes.Integer `json:"pId"` - PsID valueTypes.Integer `json:"ps_id"` + OrgId valueTypes.Integer `json:"org_id"` + ParentId valueTypes.Integer `json:"pId"` + PsId valueTypes.PsId `json:"ps_id"` ShareType int64 `json:"share_type"` } `json:"resultList"` } diff --git a/iSolarCloud/AppService/getRemoteUpgradeTaskList/data.go b/iSolarCloud/AppService/getRemoteUpgradeTaskList/data.go index 506484cad..ce26d4079 100644 --- a/iSolarCloud/AppService/getRemoteUpgradeTaskList/data.go +++ b/iSolarCloud/AppService/getRemoteUpgradeTaskList/data.go @@ -12,7 +12,7 @@ const Url = "/v1/devService/getRemoteUpgradeTaskList" const Disabled = false type RequestData struct { - PsIdList string `json:"ps_id_list" required:"true"` + PsIdList valueTypes.String `json:"ps_id_list" required:"true"` } func (rd RequestData) IsValid() error { diff --git a/iSolarCloud/AppService/getReportData/data.go b/iSolarCloud/AppService/getReportData/data.go index d7c98b923..bdcd628aa 100644 --- a/iSolarCloud/AppService/getReportData/data.go +++ b/iSolarCloud/AppService/getReportData/data.go @@ -12,7 +12,7 @@ const Url = "/v1/powerStationService/getReportData" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` ReportType string `json:"report_type" required:"true"` } @@ -32,7 +32,7 @@ type ResultData struct { InstallerPsFaultStatus valueTypes.Integer `json:"installer_ps_fault_status"` OwnerPsFaultStatus valueTypes.Integer `json:"owner_ps_fault_status"` PsFaultStatus valueTypes.Integer `json:"ps_fault_status"` - PsId valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` PsName valueTypes.String `json:"ps_name"` PsStatus valueTypes.Integer `json:"ps_status"` PsType valueTypes.Integer `json:"ps_type"` @@ -41,13 +41,13 @@ type ResultData struct { SysSchemeName valueTypes.String `json:"sys_scheme_name"` ValidFlag valueTypes.Bool `json:"valid_flag"` } `json:"info"` - MinDateID interface{} `json:"min_date_id"` + MinDateId interface{} `json:"min_date_id"` Total []DataList `json:"total" PointId:"total" PointIgnoreIfNilFromChild:"UpdateTime" PointNameFromChild:"DateId" PointNameDateFormat:"20060102" PointNameFromAppend:"true"` } type DataList struct { DateId valueTypes.DateTime `json:"date_id"` DeviceName interface{} `json:"device_name"` - PsId valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` TimeStamp interface{} `json:"time_stamp"` // Sad that this alternates between string and valueTypes.Integer. UpdateTime valueTypes.DateTime `json:"update_time"` UUID interface{} `json:"uuid"` diff --git a/iSolarCloud/AppService/getReportEmailConfigInfo/data.go b/iSolarCloud/AppService/getReportEmailConfigInfo/data.go index 3891e4613..99274238f 100644 --- a/iSolarCloud/AppService/getReportEmailConfigInfo/data.go +++ b/iSolarCloud/AppService/getReportEmailConfigInfo/data.go @@ -30,23 +30,23 @@ type ResultData struct { Email valueTypes.String `json:"email"` ReportList []struct { CreateTime valueTypes.DateTime `json:"create_time"` - CreateUserID valueTypes.Integer `json:"create_user_id"` + CreateUserId valueTypes.Integer `json:"create_user_id"` EmailAddTime valueTypes.DateTime `json:"email_add_time"` - ID valueTypes.Integer `json:"id"` + Id valueTypes.Integer `json:"id"` IsAllowEmailSend valueTypes.Bool `json:"is_allow_email_send"` IsBank valueTypes.Bool `json:"is_bank"` IsCanRenewSendConfirmEmail valueTypes.Bool `json:"is_can_renew_send_confirm_email"` IsNewWeb valueTypes.Bool `json:"is_new_web"` - OrderID valueTypes.Integer `json:"order_id"` + OrderId valueTypes.Integer `json:"order_id"` ReSendConfirmEmailTime valueTypes.DateTime `json:"re_send_confirm_email_time"` - ReportID valueTypes.Integer `json:"report_id"` + ReportId valueTypes.Integer `json:"report_id"` ReportName valueTypes.String `json:"report_name"` SendEmail valueTypes.String `json:"send_email"` Status valueTypes.Bool `json:"status"` TimeDimension valueTypes.Integer `json:"time_dimension"` Type valueTypes.Integer `json:"type"` UpdateTime valueTypes.DateTime `json:"update_time"` - UserID valueTypes.Integer `json:"user_id"` + UserId valueTypes.Integer `json:"user_id"` } `json:"report_list"` } `json:"report_email_config_info_list"` } diff --git a/iSolarCloud/AppService/getSysMsg/data.go b/iSolarCloud/AppService/getSysMsg/data.go index 4e68cff7f..67f266c87 100644 --- a/iSolarCloud/AppService/getSysMsg/data.go +++ b/iSolarCloud/AppService/getSysMsg/data.go @@ -27,7 +27,7 @@ func (rd RequestData) Help() string { type ResultData []struct { AttachNames interface{} `json:"attach_names"` AttachPath interface{} `json:"attach_path"` - BusinessID valueTypes.Integer `json:"business_id"` + BusinessId valueTypes.Integer `json:"business_id"` ClickNum valueTypes.Integer `json:"click_num"` CreateTime valueTypes.DateTime `json:"create_time"` EndTime valueTypes.DateTime `json:"end_time"` @@ -48,7 +48,7 @@ type ResultData []struct { MsgContentsTrTr valueTypes.String `json:"msg_contents_tr_tr"` MsgContentsViVn valueTypes.String `json:"msg_contents_vi_vn"` MsgContentsZhTw valueTypes.String `json:"msg_contents_zh_tw"` - MsgID valueTypes.Integer `json:"msg_id"` + MsgId valueTypes.Integer `json:"msg_id"` MsgLevel valueTypes.Integer `json:"msg_level"` MsgTitle valueTypes.String `json:"msg_title"` MsgTitleDeDe valueTypes.String `json:"msg_title_de_de"` @@ -72,8 +72,8 @@ type ResultData []struct { PublishTime valueTypes.DateTime `json:"publish_time"` RemindType valueTypes.Integer `json:"remind_type"` StartTime valueTypes.DateTime `json:"start_time"` - TypeID valueTypes.Integer `json:"type_id"` - UserID valueTypes.Integer `json:"user_id"` + TypeId valueTypes.Integer `json:"type_id"` + UserId valueTypes.Integer `json:"user_id"` UserName valueTypes.String `json:"user_name"` } diff --git a/iSolarCloud/AppService/getTemplateList/data.go b/iSolarCloud/AppService/getTemplateList/data.go index 77ada2b04..2cc9f5d54 100644 --- a/iSolarCloud/AppService/getTemplateList/data.go +++ b/iSolarCloud/AppService/getTemplateList/data.go @@ -26,7 +26,7 @@ func (rd RequestData) Help() string { type ResultData struct { PageList []struct { - TemplateID valueTypes.Integer `json:"template_id"` + TemplateId valueTypes.Integer `json:"template_id"` TemplateName valueTypes.String `json:"template_name"` UpdateTime valueTypes.DateTime `json:"update_time"` } `json:"pageList"` diff --git a/iSolarCloud/AppService/getUpTimePoint/data.go b/iSolarCloud/AppService/getUpTimePoint/data.go index bbbe538cd..4b4e40a09 100644 --- a/iSolarCloud/AppService/getUpTimePoint/data.go +++ b/iSolarCloud/AppService/getUpTimePoint/data.go @@ -29,10 +29,10 @@ type ResultData struct { PointTimeRelation []struct { Is24Hour valueTypes.Bool `json:"is_24_hour"` PointList []struct { - PointID valueTypes.Integer `json:"point_id"` + PointId valueTypes.Integer `json:"point_id"` TimeType valueTypes.Integer `json:"time_type"` } `json:"point_list"` - UpTimePointID valueTypes.Integer `json:"up_time_point_id"` + UpTimePointId valueTypes.Integer `json:"up_time_point_id"` } `json:"point_time_relation"` } diff --git a/iSolarCloud/AppService/login/auth.go b/iSolarCloud/AppService/login/auth.go index bb0a638f8..2bbc68fca 100644 --- a/iSolarCloud/AppService/login/auth.go +++ b/iSolarCloud/AppService/login/auth.go @@ -199,7 +199,7 @@ func (e *EndPoint) Print() { fmt.Printf("Login Last IP:\t%s\n", e.LoginLastIP()) fmt.Printf("Login State:\t%s\n", e.LoginState()) fmt.Printf("User Account:\t%s\n", e.UserAccount()) - fmt.Printf("User Id:\t%s\n", e.UserID()) + fmt.Printf("User Id:\t%s\n", e.UserId()) fmt.Printf("User Name:\t%s\n", e.UserName()) fmt.Printf("Is Online:\t%v\n", e.IsOnline()) fmt.Printf("Token:\t%s\n", e.Token()) diff --git a/iSolarCloud/AppService/login/data.go b/iSolarCloud/AppService/login/data.go index c2c372337..f80db12c1 100644 --- a/iSolarCloud/AppService/login/data.go +++ b/iSolarCloud/AppService/login/data.go @@ -35,13 +35,13 @@ type ResultData struct { AcceptOrderNum valueTypes.Integer `json:"accept_order_num"` BackgroundColor valueTypes.Integer `json:"background_color"` - Countryid string `json:"countryid"` - Createdate string `json:"createdate"` - Createuserid string `json:"createuserid"` + CountryId string `json:"countryid"` + CreateDate string `json:"createdate"` + CreateUserId string `json:"createuserid"` CurrentOrderNum valueTypes.Integer `json:"current_order_num"` DisableTime string `json:"disable_time"` Email string `json:"email"` - Englishname interface{} `json:"englishname"` + EnglishName interface{} `json:"englishname"` GcjLatitude valueTypes.Float `json:"gcj_latitude"` GcjLongitude valueTypes.Float `json:"gcj_longitude"` ImToken interface{} `json:"im_token"` @@ -74,14 +74,14 @@ type ResultData struct { MapType string `json:"map_type"` MinDate valueTypes.DateTime `json:"min_date"` MobileTel interface{} `json:"mobile_tel"` - OrgID string `json:"org_id"` + OrgId string `json:"org_id"` OrgName string `json:"org_name"` OrgTimezone string `json:"org_timezone"` PasswordIsSimple valueTypes.Integer `json:"password_is_simple"` - PhotoID interface{} `json:"photo_id"` + PhotoId interface{} `json:"photo_id"` PhotoURL interface{} `json:"photo_url"` Privileges []struct { - FatherID valueTypes.Integer `json:"father_id"` + FatherId valueTypes.Integer `json:"father_id"` IconURL interface{} `json:"icon_url"` IsOpen valueTypes.Bool `json:"is_open"` IsThirdPlatform valueTypes.Bool `json:"is_third_platform"` @@ -91,13 +91,13 @@ type ResultData struct { MenuOrder interface{} `json:"menu_order"` MenuType string `json:"menu_type"` MenuURL string `json:"menu_url"` - PrivilegeID valueTypes.Integer `json:"privilege_id"` - RoleID valueTypes.Integer `json:"role_id"` + PrivilegeId valueTypes.Integer `json:"privilege_id"` + RoleId valueTypes.Integer `json:"role_id"` URLTarget string `json:"url_target"` VueIcon interface{} `json:"vue_icon"` VuePath interface{} `json:"vue_path"` } `json:"privileges"` - RoleID string `json:"role_id"` + RoleId string `json:"role_id"` SecondaryOrgIds []interface{} `json:"secondaryOrgIds"` ServerTel string `json:"server_tel"` ServiceVersion string `json:"service_version"` @@ -114,14 +114,14 @@ type ResultData struct { UserAccountModifyCount valueTypes.Integer `json:"user_account_modify_count"` UserAccountModifyRemainTimes valueTypes.Integer `json:"user_account_modify_remain_times"` UserDealerOrgCode interface{} `json:"user_dealer_org_code"` - UserID string `json:"user_id"` + UserId string `json:"user_id"` UserLevel string `json:"user_level"` - UserMasterOrgID string `json:"user_master_org_id"` + UserMasterOrgId string `json:"user_master_org_id"` UserMasterOrgName string `json:"user_master_org_name"` - UserMasterOrgTimeZoneID string `json:"user_master_org_time_zone_id"` + UserMasterOrgTimeZoneId string `json:"user_master_org_time_zone_id"` UserMasterOrgTimeZoneName string `json:"user_master_org_time_zone_name"` UserName string `json:"user_name"` - UserRoleIDList []string `json:"user_role_id_list"` + UserRoleIdList []string `json:"user_role_id_list"` UserTelNationCode interface{} `json:"user_tel_nation_code"` UserauthorURL []interface{} `json:"userauthorURL"` Userauthorbutto []string `json:"userauthorbutto"` @@ -156,15 +156,11 @@ func (e *EndPoint) AppKey() string { return e.Request.RequestCommon.Appkey } -func (e *EndPoint) UserId() string { - return e.Response.ResultData.UserID -} - func (e *EndPoint) Email() string { return e.Response.ResultData.Email } func (e *EndPoint) CreateDate() string { - return e.Response.ResultData.Createdate + return e.Response.ResultData.CreateDate } func (e *EndPoint) IsOnline() bool { return e.Response.ResultData.IsOnline.Value() @@ -184,8 +180,8 @@ func (e *EndPoint) Token() string { func (e *EndPoint) UserAccount() string { return e.Response.ResultData.UserAccount } -func (e *EndPoint) UserID() string { - return e.Response.ResultData.UserID +func (e *EndPoint) UserId() string { + return e.Response.ResultData.UserId } func (e *EndPoint) UserName() string { return e.Response.ResultData.UserName diff --git a/iSolarCloud/AppService/powerDevicePointList/data.go b/iSolarCloud/AppService/powerDevicePointList/data.go index 96969e032..967bfc0a2 100644 --- a/iSolarCloud/AppService/powerDevicePointList/data.go +++ b/iSolarCloud/AppService/powerDevicePointList/data.go @@ -28,9 +28,9 @@ type ResultData struct { PageDataList []struct { CreateTime valueTypes.DateTime `json:"create_time" PointIgnore:"true"` DeviceType valueTypes.Integer `json:"device_type"` - ID valueTypes.Integer `json:"id"` + Id valueTypes.Integer `json:"id"` Period valueTypes.Integer `json:"period"` // 0, 1, 2, 3, 4 - PointID valueTypes.PointId `json:"point_id"` + PointId valueTypes.PointId `json:"point_id"` PointName valueTypes.String `json:"point_name" PointIgnore:"true"` // Old name of point. PointNameNew valueTypes.String `json:"point_name_new" PointId:"name"` TypeName valueTypes.String `json:"type_name"` diff --git a/iSolarCloud/AppService/psForcastInfo/data.go b/iSolarCloud/AppService/psForcastInfo/data.go index 2706d0079..00818e42b 100644 --- a/iSolarCloud/AppService/psForcastInfo/data.go +++ b/iSolarCloud/AppService/psForcastInfo/data.go @@ -13,7 +13,7 @@ const Url = "/v1/powerStationService/psForcastInfo" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { @@ -28,7 +28,7 @@ func (rd RequestData) Help() string { type ResultData struct { AreaForcastList []struct { - Chill valueTypes.String `json:"chill"` + Chill valueTypes.Float `json:"chill"` City valueTypes.String `json:"city"` Code valueTypes.Integer `json:"code"` CodeName valueTypes.String `json:"code_name"` @@ -57,7 +57,7 @@ type ResultData struct { } `json:"areaForcastList" PointNameFromChild:"DateTime" PointNameDateFormat:"20060102"` StationsCityCode []struct { City valueTypes.String `json:"city"` - PsID valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` PsName valueTypes.String `json:"ps_name"` } `json:"stationsCityCode"` } diff --git a/iSolarCloud/AppService/queryAllPsIdAndName/data.go b/iSolarCloud/AppService/queryAllPsIdAndName/data.go index 423bcf67f..6ac365f52 100644 --- a/iSolarCloud/AppService/queryAllPsIdAndName/data.go +++ b/iSolarCloud/AppService/queryAllPsIdAndName/data.go @@ -25,7 +25,7 @@ func (rd RequestData) Help() string { type ResultData struct { PageList []struct { - PsId valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` PsName valueTypes.String `json:"ps_name"` } `json:"pageList" PointNameFromChild:"PsId" PointNameFromAppend:"false"` } diff --git a/iSolarCloud/AppService/queryDeviceInfo/data.go b/iSolarCloud/AppService/queryDeviceInfo/data.go index 1d8674d61..da8d402d9 100644 --- a/iSolarCloud/AppService/queryDeviceInfo/data.go +++ b/iSolarCloud/AppService/queryDeviceInfo/data.go @@ -32,7 +32,7 @@ type ResultData struct { ChannelId valueTypes.Integer `json:"chnnl_id" PointId:"channel_id"` CommandStatus valueTypes.Integer `json:"command_status"` CommunicationDevUUID valueTypes.Integer `json:"communication_dev_uuid"` - CountryID interface{} `json:"country_id"` + CountryId interface{} `json:"country_id"` CpldVersion interface{} `json:"cpld_version"` DataFlagDetail valueTypes.Integer `json:"data_flag_detail"` DevFaultStatus string `json:"dev_fault_status"` @@ -53,16 +53,16 @@ type ResultData struct { DeviceArea valueTypes.String `json:"device_area"` DeviceAreaName valueTypes.String `json:"device_area_name"` DeviceCode valueTypes.Integer `json:"device_code"` - DeviceFactoryID interface{} `json:"device_factory_id"` + DeviceFactoryId interface{} `json:"device_factory_id"` DeviceModel valueTypes.String `json:"device_model"` DeviceModelCode valueTypes.String `json:"device_model_code"` - DeviceModelID valueTypes.Integer `json:"device_model_id"` + DeviceModelId valueTypes.Integer `json:"device_model_id"` DeviceName valueTypes.String `json:"device_name"` DeviceProSn valueTypes.String `json:"device_pro_sn"` DeviceStatus int64 `json:"device_status"` DeviceType int64 `json:"device_type"` FactoryName valueTypes.String `json:"factory_name"` - GridTypeID interface{} `json:"grid_type_id"` + GridTypeId interface{} `json:"grid_type_id"` InstallerDevFaultStatus interface{} `json:"installer_dev_fault_status"` InverterModelType int64 `json:"inverter_model_type"` IsCountryCheck valueTypes.Bool `json:"is_country_check"` @@ -91,7 +91,7 @@ type ResultData struct { OwnerDevFaultStatus interface{} `json:"owner_dev_fault_status"` P2 interface{} `json:"p2"` P24 interface{} `json:"p24"` - PsID valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` PsKey valueTypes.String `json:"ps_key"` PsName valueTypes.String `json:"ps_name"` PsShortName valueTypes.String `json:"ps_short_name"` diff --git a/iSolarCloud/AppService/queryDeviceInfoForApp/data.go b/iSolarCloud/AppService/queryDeviceInfoForApp/data.go index bec520908..1ca3bfc49 100644 --- a/iSolarCloud/AppService/queryDeviceInfoForApp/data.go +++ b/iSolarCloud/AppService/queryDeviceInfoForApp/data.go @@ -32,7 +32,7 @@ type ResultData struct { ChannelId valueTypes.Integer `json:"chnnl_id"` CommandStatus valueTypes.Integer `json:"command_status"` CommunicationDevUUID valueTypes.Integer `json:"communication_dev_uuid"` - CountryID interface{} `json:"country_id"` + CountryId interface{} `json:"country_id"` CpldVersion interface{} `json:"cpld_version"` DataFlagDetail valueTypes.Integer `json:"data_flag_detail"` DevFaultStatus string `json:"dev_fault_status"` @@ -40,7 +40,7 @@ type ResultData struct { DeviceModelList []struct { DeviceModel valueTypes.String `json:"device_model"` DeviceModelCode valueTypes.String `json:"device_model_code"` - ModelID valueTypes.Integer `json:"model_id"` + ModelId valueTypes.Integer `json:"model_id"` } `json:"deviceModelList"` DevicePropertyValueList []struct { DeviceType valueTypes.Integer `json:"device_type"` @@ -53,16 +53,16 @@ type ResultData struct { DeviceArea valueTypes.String `json:"device_area"` DeviceAreaName valueTypes.String `json:"device_area_name"` DeviceCode valueTypes.Integer `json:"device_code"` - DeviceFactoryID interface{} `json:"device_factory_id"` + DeviceFactoryId interface{} `json:"device_factory_id"` DeviceModel valueTypes.String `json:"device_model"` DeviceModelCode valueTypes.String `json:"device_model_code"` - DeviceModelID valueTypes.Integer `json:"device_model_id"` + DeviceModelId valueTypes.Integer `json:"device_model_id"` DeviceName valueTypes.String `json:"device_name"` DeviceProSn valueTypes.String `json:"device_pro_sn"` DeviceStatus int64 `json:"device_status"` DeviceType int64 `json:"device_type"` FactoryName valueTypes.String `json:"factory_name"` - GridTypeID interface{} `json:"grid_type_id"` + GridTypeId interface{} `json:"grid_type_id"` InstallerDevFaultStatus interface{} `json:"installer_dev_fault_status"` InverterModelType int64 `json:"inverter_model_type"` IsCountryCheck valueTypes.Bool `json:"is_country_check"` @@ -91,7 +91,7 @@ type ResultData struct { OwnerDevFaultStatus interface{} `json:"owner_dev_fault_status"` P2 interface{} `json:"p2"` P24 interface{} `json:"p24"` - PsID valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` PsKey valueTypes.String `json:"ps_key"` PsName valueTypes.String `json:"ps_name"` PsShortName valueTypes.String `json:"ps_short_name"` diff --git a/iSolarCloud/AppService/queryDeviceList/data.go b/iSolarCloud/AppService/queryDeviceList/data.go index cd450a321..3591097c6 100644 --- a/iSolarCloud/AppService/queryDeviceList/data.go +++ b/iSolarCloud/AppService/queryDeviceList/data.go @@ -13,7 +13,7 @@ const Url = "/v1/devService/queryDeviceList" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { @@ -98,9 +98,9 @@ type ResultData struct { DeviceArea valueTypes.Integer `json:"device_area" PointId:"device_area" PointUpdateFreq:"UpdateFreqBoot"` // References UUID and referenced by UUIDIndexCode DeviceAreaName valueTypes.String `json:"device_area_name" PointId:"device_area_name" PointUpdateFreq:"UpdateFreqBoot"` DeviceCode valueTypes.Integer `json:"device_code" PointId:"device_code" PointUpdateFreq:"UpdateFreqBoot"` - DeviceID valueTypes.Integer `json:"device_id" PointId:"device_id" PointUpdateFreq:"UpdateFreqBoot"` + DeviceId valueTypes.Integer `json:"device_id" PointId:"device_id" PointUpdateFreq:"UpdateFreqBoot"` DeviceModelCode valueTypes.String `json:"device_model_code" PointId:"device_model_code" PointUpdateFreq:"UpdateFreqBoot"` - DeviceModelID valueTypes.Integer `json:"device_model_id" PointId:"device_model_id" PointUpdateFreq:"UpdateFreqBoot"` + DeviceModelId valueTypes.Integer `json:"device_model_id" PointId:"device_model_id" PointUpdateFreq:"UpdateFreqBoot"` DeviceName valueTypes.String `json:"device_name" PointId:"device_name" PointUpdateFreq:"UpdateFreqBoot"` DeviceStatus valueTypes.Bool `json:"device_status" PointId:"device_status" PointUpdateFreq:"UpdateFreqInstant"` DeviceType valueTypes.Integer `json:"device_type" PointId:"device_type" PointUpdateFreq:"UpdateFreqBoot"` @@ -120,13 +120,13 @@ type ResultData struct { OwnerAlarmCount valueTypes.Count `json:"owner_alarm_count" PointId:"owner_alarm_count" PointUpdateFreq:"UpdateFreqTotal"` OwnerDevFaultStatus valueTypes.Integer `json:"owner_dev_fault_status" PointId:"owner_dev_fault_status" PointUpdateFreq:"UpdateFreqInstant"` OwnerFaultCount valueTypes.Count `json:"owner_fault_count" PointId:"owner_fault_count" PointUpdateFreq:"UpdateFreqTotal"` - PointData []PointStruct `json:"point_data" PointNameFromChild:"PointID"` + PointData []PointStruct `json:"point_data" PointNameFromChild:"PointId"` Points interface{} `json:"points" PointId:"points"` PsTimezoneInfo struct { IsDst valueTypes.Bool `json:"is_dst" PointUpdateFreq:"UpdateFreqInstant"` TimeZone valueTypes.String `json:"time_zone" PointUpdateFreq:"UpdateFreqInstant"` } `json:"psTimezoneInfo"` - PsID valueTypes.Integer `json:"ps_id" PointId:"ps_id" PointUpdateFreq:"UpdateFreqBoot"` + PsId valueTypes.PsId `json:"ps_id" PointId:"ps_id" PointUpdateFreq:"UpdateFreqBoot"` PsKey valueTypes.PsKey `json:"ps_key" PointId:"ps_key" PointUpdateFreq:"UpdateFreqBoot"` RelState valueTypes.Integer `json:"rel_state" PointId:"rel_state" PointUpdateFreq:"UpdateFreqInstant"` Sn valueTypes.String `json:"sn" PointId:"sn" PointName:"Serial Number" PointUpdateFreq:"UpdateFreqBoot"` @@ -140,16 +140,16 @@ type ResultData struct { } type PointStruct struct { - CodeID valueTypes.Integer `json:"code_id" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"` - CodeIDOrderID valueTypes.String `json:"code_id_order_id" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"` + CodeId valueTypes.Integer `json:"code_id" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"` + CodeIdOrderId valueTypes.String `json:"code_id_order_id" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"` CodeName valueTypes.String `json:"code_name" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"` DevPointLastUpdateTime valueTypes.DateTime `json:"dev_point_last_update_time" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreq5Mins"` IsPlatformDefaultUnit valueTypes.Bool `json:"is_platform_default_unit" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"` IsShow valueTypes.Bool `json:"is_show" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"` - OrderID valueTypes.Integer `json:"order_id" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"` + OrderId valueTypes.Integer `json:"order_id" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"` OrderNum valueTypes.Integer `json:"order_num" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"` - PointGroupID valueTypes.Integer `json:"point_group_id" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"` - PointGroupIDOrderID valueTypes.Integer `json:"point_group_id_order_id" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"` + PointGroupId valueTypes.Integer `json:"point_group_id" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"` + PointGroupIdOrderId valueTypes.Integer `json:"point_group_id_order_id" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"` PointName valueTypes.String `json:"point_name" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"` PointSign valueTypes.String `json:"point_sign" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"` Relate valueTypes.Integer `json:"relate" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"` @@ -158,7 +158,7 @@ type PointStruct struct { Value valueTypes.Float `json:"value" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUnitFrom:"Unit" PointUpdateFreq:"UpdateFreq5Mins"` ValueDescription valueTypes.String `json:"value_description" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"` - PointID valueTypes.PointId `json:"point_id" PointIgnore:"true" PointUpdateFreq:"UpdateFreqBoot"` + PointId valueTypes.PointId `json:"point_id" PointIgnore:"true" PointUpdateFreq:"UpdateFreqBoot"` PointGroupName valueTypes.String `json:"point_group_name" PointIgnore:"true" PointUpdateFreq:"UpdateFreqBoot"` TimeStamp valueTypes.DateTime `json:"time_stamp" PointIgnore:"true" PointUpdateFreq:"UpdateFreq5Mins"` Unit valueTypes.String `json:"unit" PointIgnore:"true" PointUpdateFreq:"UpdateFreqBoot"` @@ -236,9 +236,9 @@ func (e *EndPoint) GetData() api.DataMap { // var TotalEnergyConsumption VirtualPointStruct pkg := apiReflect.GetName("", *e) - // name := api.JoinWithDots(0, "", pkg) // , e.Request.PsId) + name := api.JoinWithDots(0, "", pkg, e.Request.PsId) dt := valueTypes.NewDateTime(valueTypes.Now) - entries.StructToPoints(e.Response.ResultData, pkg, e.Request.PsId.String(), dt) + entries.StructToPoints(e.Response.ResultData, name, e.Request.PsId.String(), dt) if len(entries.Map) == 0 { break @@ -319,9 +319,7 @@ func (e *EndPoint) GetEnergyStorageSystem(entries api.DataMap) { // Only looking for a Solar Storage System. continue } - devices = append(devices, device.PsKey.String()) - // if p.PointID.Match(13003) { - // } + devices = append(devices, api.JoinWithDots(0, "", device.PsId, device.PsKey)) } // Points are in an array. So manually add virtuals instead of using the structure. @@ -453,190 +451,6 @@ func (e *EndPoint) GetEnergyStorageSystem(entries api.DataMap) { power_load_active := entries.CopyDataEntries(*power_load, dstEndpoint, "power_load_active", "") power_load_active.FloatToState(power_load_active.GetFloat()) } - - // for _, d := range e.Response.ResultData.PageList { - // name2 := api.JoinWithDots(0, "", pkg, d.PsKey) - // entries.StructToPoints(d, name2, d.PsKey.Value(), valueTypes.NewDateTime("")) - // - // for _, p := range d.PointData { - // pid := valueTypes.SetPointIdValue(p.PointID.Value()) - // uv := valueTypes.SetUnitValueFloat(p.Value.Value(), p.Unit.Value(), "") - // // name2 := fmt.Sprintf("%s.PointData.%s", name, pid) - // // name3 := fmt.Sprintf("%s.PointData", name2) - // entries.AddUnitValue(name2, d.PsKey.Value(), pid, p.PointName.Value(), p.PointGroupName.Value(), p.TimeStamp, uv) - // - // // Handle virtual results. - // // switch pid { - // // case "13126": - // // // BatteryChargingPower - // // entries["PVPowerToBattery"] = entries[pid] - // // case "13150": - // // // BatteryDischargingPower - // // entries["BatteryPowerToLoad"] = entries[pid] - // // case "13121": - // // // TotalExportActivePower - // // entries["PVPowerToGrid"] = entries[pid] - // // case "13149": - // // // PurchasedPower - // // entries["GridPowerToLoad"] = entries[pid] - // // case "13003": - // // // TotalDcPower - // // entries["PVPower"] = addVirtualAlias(entries[pid], "pv_power", "PV Power") - // // case "13119": - // // // TotalLoadActivePower - // // entries["LoadPower"] = addVirtualAlias(entries[pid], "load_power", "Load Power") - // // - // // // addVirtualAlias(entries[pid], "FOO", "FOO") - // // - // // case "13112": - // // // Daily PV Yield - // // entries["DailyPvEnergy"] = addVirtualAlias(entries["DailyPvEnergy"], "daily_pv_energy", "Daily PV Energy") - // // case "13174": - // // // DailyBatteryChargingEnergyFromPv - // // entries["YieldBatteryCharge"] = addVirtualAlias(entries[pid], "pv_battery_charge", "PV Battery Charge") - // // case "13029": - // // // DailyBatteryDischargingEnergy - // // entries["DailyBatteryDischargingEnergy"] = entries[pid] - // // case "13122": - // // // entries["DailyFeedInEnergy"] = addVirtualAlias(entries[pid], "pv_feed_in", "PV Feed In") - // // // @TODO - This may differ from DailyFeedInEnergyPv - // // case "13173": - // // // DailyFeedInEnergyPv - // // entries["YieldFeedIn"] = addVirtualAlias(entries[pid], "pv_feed_in", "PV Feed In") - // // case "13147": - // // // DailyPurchasedEnergy - // // entries["DailyPurchasedEnergy"] = addVirtualAlias(entries[pid], "daily_purchased_energy", "Daily Purchased Energy") - // // - // // case "13116": - // // // DailyLoadEnergyConsumptionFromPv - // // entries["YieldSelfConsumption"] = addVirtualAlias(entries[pid], "pv_self_consumption", "PV Self Consumption") - // // case "13134": - // // // TotalPvYield - // // entries["TotalPvYield"] = addVirtualAlias(entries[pid], "pv_total_yield", "PV Total Yield") - // // - // // case "13199": - // // // Daily Load Energy Consumption - // // entries["DailyTotalLoad"] = addVirtualAlias(entries[pid], "daily_total_energy", "Daily Total Energy") - // // - // // case "13130": - // // // Total Load Energy Consumption - // // entries["TotalEnergyConsumption"] = addVirtualAlias(entries[pid], "total_energy_consumption", "Total Energy Consumption" - // // } - // } - // } - // - // // TotalDcPower - // entries.FromRefAddAlias(pkg + ".1171348_14_1_2.p13003.value", api.VirtualPsId, "power_pv", "") - // // BatteryChargingPower - // entries.FromRefAddAlias("p13126", api.VirtualPsId, "battery_charge_power", "") - // // BatteryDischargingPower - // entries.FromRefAddAlias("13150", api.VirtualPsId, "battery_discharge_power", "") - // // TotalExportActivePower - // entries.FromRefAddAlias("13121", api.VirtualPsId, "power_pv_to_grid", "") - // // TotalLoadActivePower - // entries.FromRefAddAlias("13119", api.VirtualPsId, "power_load", "") - // // PurchasedPower - // entries.FromRefAddAlias("13149", api.VirtualPsId, "power_grid_to_load", "") - // // Daily PV Yield - // entries.FromRefAddAlias("13112", api.VirtualPsId, "daily_pv_energy", "") - // DailyPvEnergy := entries.getFloatValue("DailyTotalLoad") - entries.getFloatValue("DailyPurchasedEnergy") - // // DailyBatteryChargingEnergyFromPv - // entries.FromRefAddAlias("13174", api.VirtualPsId, "pv_battery_charge_energy", "") - // // DailyBatteryDischargingEnergy - // entries.FromRefAddAlias("13029", api.VirtualPsId, "battery_discharge", "") - // - // @TODO - This may differ from DailyFeedInEnergyPv - // entries["DailyFeedInEnergy"] = entries.AddVirtualAliasFromRef("13122", "pv_feed_in", "PV Feed In") - // - // // DailyFeedInEnergyPv - // entries.FromRefAddAlias("13173", api.VirtualPsId, "pv_feed_in", "") - // // DailyPurchasedEnergy - // entries.FromRefAddAlias("13147", api.VirtualPsId, "daily_purchased_energy", "") - // // DailyLoadEnergyConsumptionFromPv - // entries.FromRefAddAlias("13116", api.VirtualPsId, "pv_self_consumption", "") - // // TotalPvYield - // entries.FromRefAddAlias("13134", api.VirtualPsId, "pv_total_yield", "") - // // Daily Load Energy Consumption - // entries.FromRefAddAlias("13199", api.VirtualPsId, "daily_total_energy", "") - // // Total Load Energy Consumption - // entries.FromRefAddAlias("13130", api.VirtualPsId, "total_energy_consumption", "") - // // entries.AddPointFromRef(api.Point{ Id:"queryDeviceList.p13130" }, api.Point{ PsKey:api.VirtualPsId, Id:"total_energy_consumption" }) - // - // entries.CopyEntry("p13130").CreateAlias() - // entries.GetEntry(api.Point{PsKey:psId, Id:"total_income", Unit:p.TotalIncome.Unit, Type:api.PointTypeTotal}, now, p.TotalIncome.Value) - // - // entries.FromRefAddFloat("pv_self_consumption", - // api.VirtualPsId,"pv_daily_yield", "", - // entries.GetFloatValue("pv_self_consumption", api.LastEntry) + entries.GetFloatValue("pv_battery_charge_energy", api.LastEntry) + entries.GetFloatValue("pv_feed_in", api.LastEntry)) - // - // entries.FromRefAddFloat("daily_pv_energy", - // api.VirtualPsId,"pv_self_consumption_percent", "", - // entries.GetPercent("pv_self_consumption", "daily_pv_energy", api.LastEntry)) - // entries.FromRefAddFloat("daily_pv_energy", - // api.VirtualPsId,"pv_battery_charge_percent", "", - // entries.GetPercent("pv_battery_charge_energy", "daily_pv_energy", api.LastEntry)) - // entries.FromRefAddFloat("daily_pv_energy", - // api.VirtualPsId,"pv_feed_in_percent", "", - // entries.GetPercent("pv_feed_in", "daily_pv_energy", api.LastEntry)) - // - // // // @TODO - Add this calculation. - // DailyPvEnergy := entries.GetFloatValue("daily_total_energy", api.LastEntry) - entries.GetFloatValue("daily_purchased_energy", api.LastEntry) - // // fmt.Sprintf("%f", DailyPvEnergy) - // entries.FromRefAddFloat("daily_total_energy", - // api.VirtualPsId,"daily_pv_energy_percent", "", - // api.GetPercent(DailyPvEnergy, entries.GetValue("daily_total_energy", api.LastEntry))) - // entries.FromRefAddFloat("daily_total_energy", - // api.VirtualPsId,"daily_purchased_energy_percent", "", - // entries.GetPercent("daily_purchased_energy", "daily_total_energy", api.LastEntry)) - // - // entries.FromRefAddFloat("power_pv", - // api.VirtualPsId,"power_pv_to_load", "", - // entries.GetFloatValue("power_pv", api.LastEntry) - entries.GetFloatValue("battery_charge_power", api.LastEntry) - entries.GetFloatValue("power_pv_to_grid", api.LastEntry)) - // - // // Battery - // entries.FromRefAddFloat("battery_charge_power", - // api.VirtualPsId,"power_battery", "", - // entries.LowerUpper("battery_discharge_power", "battery_charge_power", api.LastEntry)) - // entries.FromRefAddFloat("battery_charge_power", - // api.VirtualPsId,"power_pv_to_battery", "", - // entries.GetFloatValue("battery_charge_power", api.LastEntry)) - // entries.FromRefAddFloat("battery_discharge_power", - // api.VirtualPsId,"power_battery_to_load", "", - // entries.GetFloatValue("battery_charge_power", api.LastEntry)) - // entries.FromRefAddFloat("battery_charge_power", - // api.VirtualPsId,"power_battery_to_grid", "", - // 0.0) - // - // // Grid - // entries.FromRefAddFloat("power_grid_to_load", - // api.VirtualPsId,"power_grid", "", - // entries.LowerUpper("power_pv_to_grid", "power_grid_to_load", api.LastEntry)) - // entries.FromRefAddFloat("power_grid_to_load", - // api.VirtualPsId,"power_grid_to_battery", "", - // 0.0) - // - // entries.FromRefAddFloat("pv_battery_charge_energy", - // api.VirtualPsId, "battery_energy", "", - // entries.LowerUpper("pv_battery_charge_energy", "battery_discharge", api.LastEntry)) - // - // entries.FromRefAddFloat("pv_feed_in", - // api.VirtualPsId,"grid_energy", "", - // entries.LowerUpper("pv_feed_in", "daily_purchased_energy", api.LastEntry)) - // - // entries.FromRefAddState("power_pv", api.VirtualPsId,"power_pv_active", "") - // entries.FromRefAddState("power_battery", api.VirtualPsId,"power_battery_active", "") - // entries.FromRefAddState("power_grid", api.VirtualPsId,"power_grid_active", "") - // entries.FromRefAddState("power_load", api.VirtualPsId,"power_load_active", "") - // - // entries.FromRefAddState("power_pv_to_battery", api.VirtualPsId,"power_pv_to_battery_active", "") - // entries.FromRefAddState("power_pv_to_load", api.VirtualPsId,"power_pv_to_load_active", "") - // entries.FromRefAddState("power_pv_to_grid", api.VirtualPsId,"power_pv_to_grid_active", "") - // - // entries.FromRefAddState("power_battery_to_load", api.VirtualPsId,"power_battery_to_load_active", "") - // entries.FromRefAddState("power_battery_to_grid", api.VirtualPsId,"power_battery_to_grid_active", "") - // - // entries.FromRefAddState("power_grid_to_load", api.VirtualPsId,"power_grid_to_load_active", "") - // entries.FromRefAddState("power_grid_to_battery", api.VirtualPsId,"power_grid_to_battery_active", "") } } @@ -651,7 +465,7 @@ func (e *EndPoint) GetCommunicationModule(entries api.DataMap) { // Only looking for a Communication Module. continue } - devices = append(devices, device.PsKey.String()) + devices = append(devices, api.JoinWithDots(0, "", device.PsId, device.PsKey)) } // Points are in an array. So manually add virtuals instead of using the structure. @@ -677,7 +491,7 @@ func (e *EndPoint) GetBattery(entries api.DataMap) { // Only looking for a Battery. continue } - devices = append(devices, device.PsKey.String()) + devices = append(devices, api.JoinWithDots(0, "", device.PsId, device.PsKey)) } // Points are in an array. So manually add virtuals instead of using the structure. diff --git a/iSolarCloud/AppService/queryDeviceListForApp/data.go b/iSolarCloud/AppService/queryDeviceListForApp/data.go index bdb0471aa..8f58d08c7 100644 --- a/iSolarCloud/AppService/queryDeviceListForApp/data.go +++ b/iSolarCloud/AppService/queryDeviceListForApp/data.go @@ -12,7 +12,7 @@ const Url = "/v1/devService/queryDeviceListForApp" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { @@ -26,21 +26,21 @@ func (rd RequestData) Help() string { type ResultData struct { PageList []struct { - AttrID valueTypes.Integer `json:"attr_id"` + AttrId valueTypes.Integer `json:"attr_id"` ChannelId valueTypes.Integer `json:"chnnl_id" PointId:"channel_id"` CommandStatus valueTypes.Integer `json:"command_status"` ConnectState valueTypes.Integer `json:"connect_state"` DataFlag valueTypes.Integer `json:"data_flag"` DataFlagDetail valueTypes.Integer `json:"data_flag_detail"` DevFaultStatus valueTypes.Integer `json:"dev_fault_status"` - DevStatus valueTypes.Integer `json:"dev_status"` + DevStatus valueTypes.Bool `json:"dev_status"` DeviceArea valueTypes.String `json:"device_area"` DeviceCode valueTypes.Integer `json:"device_code"` DeviceFactoryDate valueTypes.DateTime `json:"device_factory_date"` - DeviceID valueTypes.Integer `json:"device_id"` + DeviceId valueTypes.Integer `json:"device_id"` DeviceModel valueTypes.String `json:"device_model"` DeviceModelCode valueTypes.String `json:"device_model_code"` - DeviceModelID valueTypes.Integer `json:"device_model_id"` + DeviceModelId valueTypes.Integer `json:"device_model_id"` DeviceName valueTypes.String `json:"device_name"` DeviceProSn valueTypes.String `json:"device_pro_sn"` DeviceState valueTypes.Integer `json:"device_state"` @@ -64,7 +64,7 @@ type ResultData struct { P24 interface{} `json:"p24"` Posx interface{} `json:"posx"` Posy interface{} `json:"posy"` - PsId valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` PsKey valueTypes.PsKey `json:"ps_key"` RelState valueTypes.Integer `json:"rel_state"` Sn valueTypes.String `json:"sn" PointName:"Serial Number"` diff --git a/iSolarCloud/AppService/queryMutiPointDataList/data.go b/iSolarCloud/AppService/queryMutiPointDataList/data.go index 04cae017e..30ea28b9f 100644 --- a/iSolarCloud/AppService/queryMutiPointDataList/data.go +++ b/iSolarCloud/AppService/queryMutiPointDataList/data.go @@ -16,7 +16,7 @@ const Url = "/v1/commonService/queryMutiPointDataList" const Disabled = false type RequestData struct { - PsID valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` PsKey valueTypes.PsKey `json:"ps_key" required:"true"` Points string `json:"points" required:"true"` MinuteInterval string `json:"minute_interval" required:"true"` diff --git a/iSolarCloud/AppService/queryPowerStationInfo/data.go b/iSolarCloud/AppService/queryPowerStationInfo/data.go index a7b98cb1e..ff906ec4c 100644 --- a/iSolarCloud/AppService/queryPowerStationInfo/data.go +++ b/iSolarCloud/AppService/queryPowerStationInfo/data.go @@ -12,7 +12,7 @@ const Url = "/v1/powerStationService/queryPowerStationInfo" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` Sn valueTypes.String `json:"sn"` } @@ -26,20 +26,20 @@ func (rd RequestData) Help() string { } type ResultData struct { - LbsAreaCode interface{} `json:"LbsAreaCode"` - LbsCountry interface{} `json:"LbsCountry"` + LbsAreaCode interface{} `json:"LbsAreaCode" PointId:"lbs_area_code"` + LbsCountry interface{} `json:"LbsCountry" PointId:"lbs_country"` AccessType interface{} `json:"access_type"` - AreaID interface{} `json:"area_id"` + AreaId interface{} `json:"area_id"` ArrearsStatus valueTypes.Integer `json:"arrears_status"` BatteryType valueTypes.String `json:"battery_type"` - CityCode interface{} `json:"city_code"` - CityName interface{} `json:"city_name"` + CityCode valueTypes.String `json:"city_code"` + CityName valueTypes.String `json:"city_name"` ComponentArea interface{} `json:"component_area"` ComponentStatus valueTypes.Integer `json:"component_status"` ConnectType valueTypes.Integer `json:"connect_type"` ConnectTypeDesc valueTypes.String `json:"connect_type_desc"` ContactName valueTypes.String `json:"contact_name"` - CountryID valueTypes.Integer `json:"country_id"` + CountryId valueTypes.Integer `json:"country_id"` Description interface{} `json:"description"` DesignCapacity valueTypes.Float `json:"design_capacity" PointUnit:"W"` // @TODO - When this is set to valueTypes.Integer, we get a failure. DesignCapacityBattery valueTypes.Float `json:"design_capacity_battery" PointUnit:"W"` @@ -74,9 +74,9 @@ type ResultData struct { MapLatitude valueTypes.Float `json:"map_latitude"` MapLongitude valueTypes.Float `json:"map_longitude"` MlpeFlag valueTypes.Bool `json:"mlpe_flag"` - MobleTel interface{} `json:"moble_tel"` - MobleTelBak interface{} `json:"moble_tel_bak"` - ModuleModelID interface{} `json:"module_model_id"` + MobileTel interface{} `json:"moble_tel" PointId:"mobile_tel"` + MobileTelBak interface{} `json:"moble_tel_bak" PointId:"mobile_tel_bak"` + ModuleModelId interface{} `json:"module_model_id"` ModuleModelName interface{} `json:"module_model_name"` Nmi valueTypes.String `json:"nmi"` OperationBusName interface{} `json:"operation_bus_name"` @@ -87,16 +87,16 @@ type ResultData struct { ProvinceCode interface{} `json:"province_code"` ProvinceName interface{} `json:"province_name"` PsBuildDate valueTypes.DateTime `json:"ps_build_date"` - PsCountryID valueTypes.Integer `json:"ps_country_id"` - PsCreateUserID valueTypes.Integer `json:"ps_create_user_id"` + PsCountryId valueTypes.Integer `json:"ps_country_id"` + PsCreateUserId valueTypes.Integer `json:"ps_create_user_id"` PsCurrentTimeZone valueTypes.String `json:"ps_current_time_zone"` PsDirectOrgList []struct { - OrgID valueTypes.Integer `json:"org_id"` + OrgId valueTypes.Integer `json:"org_id"` OrgIndexCode valueTypes.String `json:"org_index_code"` OrgName valueTypes.String `json:"org_name"` } `json:"ps_direct_org_list"` PsHolder valueTypes.String `json:"ps_holder"` - PsID valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` PsInstalledPower valueTypes.Float `json:"ps_installed_power"` PsKey valueTypes.PsKey `json:"ps_key"` PsLocation valueTypes.String `json:"ps_location"` @@ -106,48 +106,48 @@ type ResultData struct { Installer valueTypes.String `json:"installer"` InstallerEmail valueTypes.String `json:"installer_email"` InstallerPhone valueTypes.String `json:"installer_phone"` - OrgID valueTypes.Integer `json:"org_id"` + OrgId valueTypes.Integer `json:"org_id"` OrgIndexCode valueTypes.String `json:"org_index_code"` OrgName valueTypes.String `json:"org_name"` PsDealerOrgCode valueTypes.String `json:"ps_dealer_org_code"` - UpOrgID valueTypes.Integer `json:"up_org_id"` + UpOrgId valueTypes.Integer `json:"up_org_id"` } `json:"ps_org_info"` - PsPrice valueTypes.Float `json:"ps_price"` - PsPriceKwh valueTypes.Float `json:"ps_price_kwh"` + PsPrice valueTypes.Float `json:"ps_price" PointUnitFrom:"ParamIncomeUnitName"` + PsPriceKwh valueTypes.Float `json:"ps_price_kwh" PointUnitFrom:"ParamIncomeUnitName"` PsType valueTypes.Integer `json:"ps_type"` PsTypeDesc valueTypes.String `json:"ps_type_desc"` PsTypeName valueTypes.String `json:"ps_type_name"` - PsUserID valueTypes.Integer `json:"ps_user_id"` - RecoreCreateTime valueTypes.DateTime `json:"recore_create_time"` + PsUserId valueTypes.Integer `json:"ps_user_id"` + RecordCreateTime valueTypes.DateTime `json:"recore_create_time" PointId:"record_create_time"` SafeStartDate valueTypes.DateTime `json:"safe_start_date"` SelectedOrgList []struct { - OrgID valueTypes.Integer `json:"org_id"` + OrgId valueTypes.Integer `json:"org_id"` OrgIndexCode valueTypes.String `json:"org_index_code"` OrgName valueTypes.String `json:"org_name"` - } `json:"selectedOrgList"` + } `json:"selectedOrgList" PointId:"selected_org_list"` SetUserOrg valueTypes.Integer `json:"set_user_org"` ShareType valueTypes.Integer `json:"share_type"` ShareUserType interface{} `json:"share_user_type"` ShippingAddress valueTypes.String `json:"shipping_address"` ShippingZipCode valueTypes.String `json:"shipping_zip_code"` - Sn valueTypes.String `json:"sn"` + Sn valueTypes.String `json:"sn" PointName:"Serial Number"` SnDetailList []struct { CommunicateDeviceType valueTypes.Integer `json:"communicate_device_type"` CommunicateDeviceTypeName valueTypes.String `json:"communicate_device_type_name"` - ID valueTypes.Integer `json:"id"` + Id valueTypes.Integer `json:"id"` IsEnable valueTypes.Bool `json:"is_enable"` Sn valueTypes.String `json:"sn"` } `json:"sn_detail_list"` SummerTimeState valueTypes.Bool `json:"summer_time_state"` SummerTimeZone valueTypes.String `json:"summer_time_zone"` - SummerTimeZoneID valueTypes.Integer `json:"summer_time_zone_id"` - TimeZoneID valueTypes.Integer `json:"time_zone_id"` + SummerTimeZoneId valueTypes.Integer `json:"summer_time_zone_id"` + TimeZoneId valueTypes.Integer `json:"time_zone_id"` Timezone valueTypes.String `json:"timezone"` UserAccount valueTypes.String `json:"user_account"` UserCapacityStatus valueTypes.Integer `json:"user_capacity_status"` UserEnglishName interface{} `json:"user_english_name"` UserLanguage valueTypes.String `json:"user_language"` - UserMobleTel interface{} `json:"user_moble_tel"` + UserMobileTel interface{} `json:"user_moble_tel" PointId:"user_mobile_tel"` UserName valueTypes.String `json:"user_name"` UserTelNationCode interface{} `json:"user_tel_nation_code"` ValidFlag valueTypes.Bool `json:"valid_flag"` diff --git a/iSolarCloud/AppService/queryPsNameByPsId/data.go b/iSolarCloud/AppService/queryPsNameByPsId/data.go index 2c9be6942..c9f60917b 100644 --- a/iSolarCloud/AppService/queryPsNameByPsId/data.go +++ b/iSolarCloud/AppService/queryPsNameByPsId/data.go @@ -13,7 +13,7 @@ const Url = "/v1/devService/queryPsNameByPsId" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { diff --git a/iSolarCloud/AppService/queryPsProfit/data.go b/iSolarCloud/AppService/queryPsProfit/data.go index d0fcb15b3..94cde8b74 100644 --- a/iSolarCloud/AppService/queryPsProfit/data.go +++ b/iSolarCloud/AppService/queryPsProfit/data.go @@ -12,8 +12,8 @@ const Url = "/v1/powerStationService/queryPsProfit" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` - DateID string `json:"date_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` + DateId string `json:"date_id" required:"true"` DateType string `json:"date_type" required:"true"` } @@ -41,7 +41,7 @@ type ResultData struct { CuspNetPowerQuantity interface{} `json:"cusp_net_power_quantity"` CuspPowerQuantity interface{} `json:"cusp_power_quantity"` CuspUsePowerQuantity interface{} `json:"cusp_use_power_quantity"` - DateID valueTypes.DateTime `json:"date_id"` + DateId valueTypes.DateTime `json:"date_id"` FlatNetPowerQuantity valueTypes.Float `json:"flat_net_power_quantity"` FlatPowerQuantity valueTypes.Float `json:"flat_power_quantity"` FlatUsePowerQuantity valueTypes.Float `json:"flat_use_power_quantity"` diff --git a/iSolarCloud/AppService/queryPsProfit/struct.go b/iSolarCloud/AppService/queryPsProfit/struct.go index da90da63f..ba71257fd 100644 --- a/iSolarCloud/AppService/queryPsProfit/struct.go +++ b/iSolarCloud/AppService/queryPsProfit/struct.go @@ -335,22 +335,6 @@ func (e EndPoint) CacheFilename() string { return e.ApiCacheFilename(e.Request.RequestData) } -// // CheckCache - Check if a cache file exists for this EndPoint. -// func (e EndPoint) CheckCache() bool { -// return e.ApiCheckCache(e.Request.RequestData) -// } -// -// // ReadCache - Read a cache file and return it as an EndPoint structure. -// func (e EndPoint) ReadCache() api.EndPoint { -// e.Error = e.ApiReadCache(e.Request.RequestData, &e) -// return e -// } -// -// // WriteCache - Write this EndPoint structure out to a cache file. -// func (e EndPoint) WriteCache() error { -// return e.ApiWriteCache(e.Request.RequestData, e) -// } - // SetCacheTimeout - Set the cache timeout for this EndPoint. (Defaults to 1 hour.) func (e EndPoint) SetCacheTimeout(duration time.Duration) api.EndPoint { e.ApiRoot.SetCacheTimeout(duration) diff --git a/iSolarCloud/AppService/queryUnitList/data.go b/iSolarCloud/AppService/queryUnitList/data.go index 58d32db1a..568f7fc65 100644 --- a/iSolarCloud/AppService/queryUnitList/data.go +++ b/iSolarCloud/AppService/queryUnitList/data.go @@ -27,7 +27,7 @@ func (rd RequestData) Help() string { type ResultData []struct { IsBasicUnit valueTypes.Bool `json:"is_basic_unit"` TargetUnit string `json:"target_unit"` - UnitConverID valueTypes.Integer `json:"unit_conver_id"` + UnitConverId valueTypes.Integer `json:"unit_conver_id"` UnitName string `json:"unit_name"` UnitType valueTypes.Integer `json:"unit_type"` } diff --git a/iSolarCloud/AppService/queryUserList/data.go b/iSolarCloud/AppService/queryUserList/data.go index 33b631dca..7636404d3 100644 --- a/iSolarCloud/AppService/queryUserList/data.go +++ b/iSolarCloud/AppService/queryUserList/data.go @@ -24,7 +24,7 @@ func (rd RequestData) Help() string { } type ResultData []struct { - UserID valueTypes.Integer `json:"user_id"` + UserId valueTypes.Integer `json:"user_id"` UserName string `json:"user_name"` } diff --git a/iSolarCloud/AppService/reportList/data.go b/iSolarCloud/AppService/reportList/data.go index eb6b3f787..a81a991d0 100644 --- a/iSolarCloud/AppService/reportList/data.go +++ b/iSolarCloud/AppService/reportList/data.go @@ -12,10 +12,8 @@ const Url = "/v1/powerStationService/reportList" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id"` - ReportType string `json:"report_type"` - // DateID string `json:"date_id,omitempty"` - // DateType string `json:"date_type,omitempty"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` + ReportType string `json:"report_type" required:"true"` } func (rd RequestData) IsValid() error { @@ -23,7 +21,11 @@ func (rd RequestData) IsValid() error { } func (rd RequestData) Help() string { - ret := fmt.Sprintf("report_type: ") + ret := fmt.Sprintf("report_type is from 1-4") + ret += fmt.Sprintf("1: Day Report.") + ret += fmt.Sprintf("2: Month Report.") + ret += fmt.Sprintf("3: Year Report.") + ret += fmt.Sprintf("4: Total Report.") return ret } @@ -34,7 +36,7 @@ type ResultData struct { InstallerPsFaultStatus valueTypes.Integer `json:"installer_ps_fault_status"` OwnerPsFaultStatus valueTypes.Integer `json:"owner_ps_fault_status"` PsFaultStatus valueTypes.Integer `json:"ps_fault_status"` - PsId valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` PsName valueTypes.String `json:"ps_name"` PsStatus valueTypes.Integer `json:"ps_status"` PsType valueTypes.Integer `json:"ps_type"` @@ -43,14 +45,14 @@ type ResultData struct { SysSchemeName valueTypes.String `json:"sys_scheme_name"` ValidFlag valueTypes.Bool `json:"valid_flag"` } `json:"info"` - MinDateID interface{} `json:"min_date_id"` - Total []DataList `json:"total" PointId:"total" PointIgnoreIfNilFromChild:"UpdateTime" PointNameFromChild:"DateId" PointNameDateFormat:"20060102" PointNameFromAppend:"true"` + MinDateId interface{} `json:"min_date_id"` + Total []DataList `json:"total" PointId:"total" PointIgnoreIfNilFromChild:"UpdateTime" PointNameFromChild:"UpdateTime" PointNameDateFormat:"20060102" PointNameFromAppend:"true"` } type DataList struct { DateId valueTypes.DateTime `json:"date_id"` DeviceName interface{} `json:"device_name"` - PsId valueTypes.Integer `json:"ps_id"` + PsId valueTypes.PsId `json:"ps_id"` TimeStamp interface{} `json:"time_stamp"` // Sad that this alternates between string and valueTypes.Integer. UpdateTime valueTypes.DateTime `json:"update_time"` UUID interface{} `json:"uuid"` diff --git a/iSolarCloud/WebAppService/getPsIdState/data.go b/iSolarCloud/WebAppService/getPsIdState/data.go index 551688bb8..d27c99975 100644 --- a/iSolarCloud/WebAppService/getPsIdState/data.go +++ b/iSolarCloud/WebAppService/getPsIdState/data.go @@ -12,7 +12,7 @@ const Url = "/v1/powerStationService/getPsIdState" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { diff --git a/iSolarCloud/WebAppService/getReportInfoByReportId/data.go b/iSolarCloud/WebAppService/getReportInfoByReportId/data.go index 321e93541..e08eacd4b 100644 --- a/iSolarCloud/WebAppService/getReportInfoByReportId/data.go +++ b/iSolarCloud/WebAppService/getReportInfoByReportId/data.go @@ -4,16 +4,15 @@ import ( "GoSungrow/iSolarCloud/api" "GoSungrow/iSolarCloud/api/apiReflect" "GoSungrow/iSolarCloud/api/valueTypes" - "github.com/MickMake/GoUnify/Only" - "errors" "fmt" + "github.com/MickMake/GoUnify/Only" ) const Url = "/v1/reportService/getReportInfoByReportId" -const Disabled = true +const Disabled = false type RequestData struct { - // DeviceType string `json:"device_type" required:"true"` + ReportId valueTypes.String `json:"report_id" required:"true"` } func (rd RequestData) IsValid() error { @@ -25,46 +24,43 @@ func (rd RequestData) Help() string { return ret } - -type ResultData struct { - Dummy string `json:"dummy"` +type ResultData []struct { + CreateUserID valueTypes.Integer `json:"create_user_id"` + ID valueTypes.Integer `json:"id"` + ReportID valueTypes.Integer `json:"report_id"` + ReportName valueTypes.String `json:"report_name"` + ReportPsType valueTypes.Integer `json:"report_ps_type"` + ReportTemplatePeriod valueTypes.Integer `json:"report_template_period"` + ReportTemplateType valueTypes.Integer `json:"report_template_type"` + PsIDList interface{} `json:"ps_id_list"` + SamplingPeriod interface{} `json:"sampling_period"` + TimeDimension valueTypes.Integer `json:"time_dimension"` + UserIds valueTypes.Integer `json:"user_ids"` + PointColumn valueTypes.String `json:"point_column" PointSplitOn:","` + PointName valueTypes.String `json:"point_name" PointSplitOn:","` + Ratio valueTypes.String `json:"ratio" PointSplitOn:","` + ReportTemplatePoint valueTypes.String `json:"report_template_point" PointSplitOn:","` } func (e *ResultData) IsValid() error { var err error - switch { - case e.Dummy == "": - break - default: - err = errors.New(fmt.Sprintf("unknown error '%s'", e.Dummy)) - } + // switch { + // case e.Dummy == "": + // break + // default: + // err = errors.New(fmt.Sprintf("unknown error '%s'", e.Dummy)) + // } return err } -//type DecodeResultData ResultData -// -//func (e *ResultData) UnmarshalJSON(data []byte) error { -// var err error -// -// for range Only.Once { -// if len(data) == 0 { -// break -// } -// var pd DecodeResultData -// -// // Store ResultData -// _ = json.Unmarshal(data, &pd) -// e.Dummy = pd.Dummy -// } -// -// return err -//} - func (e *EndPoint) GetData() api.DataMap { entries := api.NewDataMap() for range Only.Once { - entries.StructToPoints(e.Response.ResultData, apiReflect.GetName("", *e), "system", valueTypes.NewDateTime("")) + pkg := apiReflect.GetName("", *e) + dt := valueTypes.NewDateTime(valueTypes.Now) + name := pkg + "." + e.Request.ReportId.String() + entries.StructToPoints(e.Response.ResultData, name, e.Request.ReportId.String(), dt) } return entries diff --git a/iSolarCloud/WebAppService/getReportListByType/data.go b/iSolarCloud/WebAppService/getReportListByType/data.go index 483e233df..2c0c1bfd9 100644 --- a/iSolarCloud/WebAppService/getReportListByType/data.go +++ b/iSolarCloud/WebAppService/getReportListByType/data.go @@ -4,13 +4,12 @@ import ( "GoSungrow/iSolarCloud/api" "GoSungrow/iSolarCloud/api/apiReflect" "GoSungrow/iSolarCloud/api/valueTypes" - "github.com/MickMake/GoUnify/Only" - "errors" "fmt" + "github.com/MickMake/GoUnify/Only" ) const Url = "/v1/reportService/getReportListByType" -const Disabled = true +const Disabled = false type RequestData struct { // DeviceType string `json:"device_type" required:"true"` @@ -26,45 +25,37 @@ func (rd RequestData) Help() string { } -type ResultData struct { - Dummy string `json:"dummy"` +type ResultData []struct { + CreateTime valueTypes.DateTime `json:"create_time"` + Cycle valueTypes.Integer `json:"cycle"` + ID valueTypes.Integer `json:"id"` + MonthDate valueTypes.String `json:"month_date"` + PsID valueTypes.PsId `json:"ps_id"` + ReportName valueTypes.String `json:"report_name"` + ReportType valueTypes.Integer `json:"report_type"` + Status valueTypes.Bool `json:"status"` + UpdateTime valueTypes.DateTime `json:"update_time"` } func (e *ResultData) IsValid() error { var err error - switch { - case e.Dummy == "": - break - default: - err = errors.New(fmt.Sprintf("unknown error '%s'", e.Dummy)) - } + // switch { + // case e.Dummy == "": + // break + // default: + // err = errors.New(fmt.Sprintf("unknown error '%s'", e.Dummy)) + // } return err } -//type DecodeResultData ResultData -// -//func (e *ResultData) UnmarshalJSON(data []byte) error { -// var err error -// -// for range Only.Once { -// if len(data) == 0 { -// break -// } -// var pd DecodeResultData -// -// // Store ResultData -// _ = json.Unmarshal(data, &pd) -// e.Dummy = pd.Dummy -// } -// -// return err -//} - func (e *EndPoint) GetData() api.DataMap { entries := api.NewDataMap() for range Only.Once { - entries.StructToPoints(e.Response.ResultData, apiReflect.GetName("", *e), "system", valueTypes.NewDateTime("")) + pkg := apiReflect.GetName("", *e) + dt := valueTypes.NewDateTime(valueTypes.Now) + // name := pkg + "." + e.Request.DateId.Format(valueTypes.DateTimeLayoutDay) + entries.StructToPoints(e.Response.ResultData, pkg, "system", dt) } return entries diff --git a/iSolarCloud/WebAppService/getReportPsTree/data.go b/iSolarCloud/WebAppService/getReportPsTree/data.go index 9d7d05a80..ca535549d 100644 --- a/iSolarCloud/WebAppService/getReportPsTree/data.go +++ b/iSolarCloud/WebAppService/getReportPsTree/data.go @@ -4,16 +4,16 @@ import ( "GoSungrow/iSolarCloud/api" "GoSungrow/iSolarCloud/api/apiReflect" "GoSungrow/iSolarCloud/api/valueTypes" - "github.com/MickMake/GoUnify/Only" "errors" "fmt" + "github.com/MickMake/GoUnify/Only" ) const Url = "/v1/reportService/getReportPsTree" -const Disabled = true +const Disabled = false type RequestData struct { - // DeviceType string `json:"device_type" required:"true"` + DeviceType string `json:"device_type" required:"true"` } func (rd RequestData) IsValid() error { @@ -41,30 +41,14 @@ func (e *ResultData) IsValid() error { return err } -//type DecodeResultData ResultData -// -//func (e *ResultData) UnmarshalJSON(data []byte) error { -// var err error -// -// for range Only.Once { -// if len(data) == 0 { -// break -// } -// var pd DecodeResultData -// -// // Store ResultData -// _ = json.Unmarshal(data, &pd) -// e.Dummy = pd.Dummy -// } -// -// return err -//} - func (e *EndPoint) GetData() api.DataMap { entries := api.NewDataMap() for range Only.Once { - entries.StructToPoints(e.Response.ResultData, apiReflect.GetName("", *e), "system", valueTypes.NewDateTime("")) + pkg := apiReflect.GetName("", *e) + dt := valueTypes.NewDateTime(valueTypes.Now) + // name := pkg + "." + e.Request.DateId.Format(valueTypes.DateTimeLayoutDay) + entries.StructToPoints(e.Response.ResultData, pkg, "system", dt) } return entries diff --git a/iSolarCloud/WebAppService/queryUserCurveTemplateData/data.go b/iSolarCloud/WebAppService/queryUserCurveTemplateData/data.go index 1288b9802..4b9373332 100644 --- a/iSolarCloud/WebAppService/queryUserCurveTemplateData/data.go +++ b/iSolarCloud/WebAppService/queryUserCurveTemplateData/data.go @@ -15,7 +15,7 @@ const Disabled = false // {"template_id":"","date_type":"","start_time":"","end_time":""} type RequestData struct { - TemplateID string `json:"template_id" required:"true"` + TemplateId string `json:"template_id" required:"true"` // DateType string `json:"date_type" required:"true"` // StartTime string `json:"start_time" required:"true"` // EndTime string `json:"end_time" required:"true"` @@ -48,7 +48,7 @@ type ResultData struct { OpenTime string `json:"open_time"` PointsData PointsData `json:"points_data"` StartTime string `json:"start_time"` - TemplateID string `json:"template_id"` + TemplateId string `json:"template_id"` TemplateName string `json:"template_name"` UpdateTime string `json:"update_time"` } @@ -116,7 +116,7 @@ func (p *DeviceData) UnmarshalJSON(data []byte) error { // Store DeviceData.Points _ = json.Unmarshal(data, &dd.Points) for i, k := range dd.Points { - if k.PointID.String() == "" { + if k.PointId.String() == "" { delete(dd.Points, i) continue } @@ -135,11 +135,11 @@ type Point struct { TimeStamp string `json:"time_stamp"` Value string `json:"value"` } `json:"data_list"` - DetailID string `json:"detail_id"` - PointID valueTypes.PointId `json:"point_id"` + DetailId string `json:"detail_id"` + PointId valueTypes.PointId `json:"point_id"` PointName string `json:"point_name"` - PsID string `json:"ps_id"` - PsKey string `json:"ps_key"` + PsId valueTypes.PsId `json:"ps_id"` + PsKey valueTypes.PsKey `json:"ps_key"` PsName string `json:"ps_name"` Statistics string `json:"statistics"` Style string `json:"style"` diff --git a/iSolarCloud/WebAppService/showPSView/data.go b/iSolarCloud/WebAppService/showPSView/data.go index 8251573af..20e009b5c 100644 --- a/iSolarCloud/WebAppService/showPSView/data.go +++ b/iSolarCloud/WebAppService/showPSView/data.go @@ -12,7 +12,7 @@ const Url = "/v1/powerStationService/showPSView" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { diff --git a/iSolarCloud/WebIscmAppService/getMaxDeviceIdByPsId/data.go b/iSolarCloud/WebIscmAppService/getMaxDeviceIdByPsId/data.go index d9a905887..4c451c6fc 100644 --- a/iSolarCloud/WebIscmAppService/getMaxDeviceIdByPsId/data.go +++ b/iSolarCloud/WebIscmAppService/getMaxDeviceIdByPsId/data.go @@ -12,7 +12,7 @@ const Url = "/v1/devService/getMaxDeviceIdByPsId" const Disabled = false type RequestData struct { - PsId valueTypes.Integer `json:"ps_id" required:"true"` + PsId valueTypes.PsId `json:"ps_id" required:"true"` } func (rd RequestData) IsValid() error { @@ -26,7 +26,7 @@ func (rd RequestData) Help() string { type ResultData struct { - MaxDeviceID valueTypes.Integer `json:"max_device_id"` + MaxDeviceId valueTypes.Integer `json:"max_device_id"` } func (e *ResultData) IsValid() error { diff --git a/iSolarCloud/api/apiReflect/reflect.go b/iSolarCloud/api/apiReflect/reflect.go index 99769f5a2..879741e31 100644 --- a/iSolarCloud/api/apiReflect/reflect.go +++ b/iSolarCloud/api/apiReflect/reflect.go @@ -19,42 +19,45 @@ import ( const ( - PointId = "PointId" // Point id in the form p\d+ or \d+ - PointParentId = "PointParentId" // Associated parent of point. - PointUpdateFreq = "PointUpdateFreq" // Point update frequency - Total, Yearly, Monthly, Day. - PointValueType = "PointValueType" // Value type of point: energy, date, battery, temperature. - PointIgnore = "PointIgnore" // Ignore this point. - PointIgnoreIfNil = "PointIgnoreIfNil" // Ignore this point if a child is nil or empty. + PointId = "PointId" // Point id in the form p\d+ or \d+ + PointParentId = "PointParentId" // Associated parent of point. + PointUpdateFreq = "PointUpdateFreq" // Point update frequency - Total, Yearly, Monthly, Day. + PointValueType = "PointValueType" // Value type of point: energy, date, battery, temperature. + PointIgnore = "PointIgnore" // Ignore this point. + PointIgnoreIfNil = "PointIgnoreIfNil" // Ignore this point if a child is nil or empty. PointIgnoreIfNilFromChild = "PointIgnoreIfNilFromChild" // Ignore this point if a child is nil or empty. - PointAliasTo = "PointAliasTo" // Alias this point to another point. - PointAliasFrom = "PointAliasFrom" // Alias this point from another point. + PointAliasTo = "PointAliasTo" // Alias this point to another point. + PointAliasFrom = "PointAliasFrom" // Alias this point from another point. PointUnit = "PointUnit" // Units: Wh, kWh, C, h. PointUnitFrom = "PointUnitFrom" // Get PointUnit from another field structure. + PointUnitFromParent = "PointUnitFromParent" // Get PointUnit from another parent field structure. - PointGroupName = "PointGroupName" // Point group name. - PointGroupNameFrom = "PointGroupNameFrom" // Get PointGroupName from another field structure. + PointGroupName = "PointGroupName" // Point group name. + PointGroupNameFrom = "PointGroupNameFrom" // Get PointGroupName from another field structure. PointName = "PointName" // Human-readable name of point. PointNameFromChild = "PointNameFromChild" // Searches child for field value to use for naming when hitting a slice, (as opposed to using an index). PointNameFromParent = "PointNameFromParent" // Searches child for field value to use for naming when hitting a slice, (as opposed to using an index). PointNameDateFormat = "PointNameDateFormat" // Date format when using PointNameFrom, (if the field is a time.Time type). - PointNameFromAppend = "PointNameFromAppend" // Append PointNameFrom instead of replace. + PointNameFromAppend = "PointNameFromAppend" // Append PointNameFrom instead of replace. - PointArrayFlatten = "PointArrayFlatten" // Flatten an array into a string. EG: ["one", "two", "three"] - PointIgnoreZero = "PointIgnoreZero" // Ignore arrays with zero size, (default true). + PointArrayFlatten = "PointArrayFlatten" // Flatten an array into a string. EG: ["one", "two", "three"] + PointSplitOn = "PointSplitOn" // Split a point into an array separating by defined string. + PointSplitOnType = "PointSplitOnType" // What valueTypes will be used for a split. + PointIgnoreZero = "PointIgnoreZero" // Ignore arrays with zero size, (default true). - PointTimestampFrom = "PointTimestampFrom" // Pull timestamp from another field structure. + PointTimestampFrom = "PointTimestampFrom" // Pull timestamp from another field structure. ) const ( UpdateFreqInstant = "instant" UpdateFreq5Mins = "5mins" UpdateFreqBoot = "boot" - UpdateFreqDay = "daily" - UpdateFreqMonth = "monthly" - UpdateFreqYear = "yearly" + UpdateFreqDay = "daily" + UpdateFreqMonth = "monthly" + UpdateFreqYear = "yearly" UpdateFreqTotal = "total" ) @@ -62,6 +65,7 @@ const ( type Reflect struct { Valid bool DataStructure DataStructure + Parent interface{} Interface interface{} IsNil bool IsExported bool @@ -76,14 +80,15 @@ type Reflect struct { FieldVo reflect.Value } -func (r *Reflect) SetByFieldName(parent interface{}, ref interface{}, fieldName string) { // , fieldTo reflect.StructField, fieldVo reflect.Value) { +func (r *Reflect) SetByFieldName(parent interface{}, current interface{}, fieldName string) { // , fieldTo reflect.StructField, fieldVo reflect.Value) { for range Only.Once { r.Valid = true - r.Interface = ref - r.IsNil = valueTypes.IsNil(ref) - r.IsUnknown = valueTypes.IsUnknownStruct(ref) - r.TypeOf = reflect.TypeOf(ref) - r.ValueOf = reflect.ValueOf(ref) + r.Parent = parent + r.Interface = current + r.IsNil = valueTypes.IsNil(current) + r.IsUnknown = valueTypes.IsUnknownStruct(current) + r.TypeOf = reflect.TypeOf(current) + r.ValueOf = reflect.ValueOf(current) r.Kind = r.TypeOf.Kind() r.FieldName = fieldName @@ -103,16 +108,41 @@ func (r *Reflect) SetByFieldName(parent interface{}, ref interface{}, fieldName r.Length = len(r.ValueOf.MapKeys()) } - r.SetFieldName(parent, fieldName) + r.SetFieldName(parent, current, fieldName) // r.DataStructure = r.DataStructure.Set(ref, r.FieldTo, r.FieldVo) } } -func (r *Reflect) SetByIndex(parent interface{}, fieldIndex int) { +func (r *Reflect) SetFieldName(parent interface{}, current interface{}, fieldName string) { // , fieldTo reflect.StructField, fieldVo reflect.Value) { + for range Only.Once { + if fieldName == "" { + break + } + + p := reflect.TypeOf(current) + if p.Kind() != reflect.Struct { + break + } + + + sf, ok := p.FieldByName(fieldName) + if !ok { + break + } + + r.FieldTo = sf + r.IsExported = r.FieldTo.IsExported() + r.FieldVo = reflect.ValueOf(current).FieldByName(fieldName) + + r.DataStructure = r.DataStructure.Set(parent, current, r.FieldTo, r.FieldVo) + } +} + +func (r *Reflect) SetByIndex(parent interface{}, current interface{}, fieldIndex int) { for range Only.Once { // Get child interface from parent. - pt := reflect.TypeOf(parent) - pv := reflect.ValueOf(parent) + pt := reflect.TypeOf(current) + pv := reflect.ValueOf(current) pk := pt.Kind() switch pk { case reflect.Struct: @@ -127,6 +157,7 @@ func (r *Reflect) SetByIndex(parent interface{}, fieldIndex int) { } r.Valid = true + r.Parent = parent r.IsNil = valueTypes.IsNil(r.Interface) r.IsUnknown = valueTypes.IsUnknownStruct(r.Interface) r.TypeOf = reflect.TypeOf(r.Interface) @@ -151,63 +182,38 @@ func (r *Reflect) SetByIndex(parent interface{}, fieldIndex int) { r.Length = len(r.ValueOf.MapKeys()) } - r.SetFieldNameByIndex(parent, fieldIndex) + r.SetFieldNameByIndex(parent, current, fieldIndex) // r.DataStructure = r.DataStructure.Set(ref, r.FieldTo, r.FieldVo) } } -func (r *Reflect) SetFieldName(parent interface{}, fieldName string) { // , fieldTo reflect.StructField, fieldVo reflect.Value) { +func (r *Reflect) SetFieldNameByIndex(parent interface{}, current interface{}, fieldIndex int) { // , fieldTo reflect.StructField, fieldVo reflect.Value) { for range Only.Once { - if fieldName == "" { - break - } - - p := reflect.TypeOf(parent) - if p.Kind() != reflect.Struct { - break - } - - - sf, ok := p.FieldByName(fieldName) - if !ok { - break - } - - r.FieldTo = sf - r.IsExported = r.FieldTo.IsExported() - r.FieldVo = reflect.ValueOf(parent).FieldByName(fieldName) - - r.DataStructure = r.DataStructure.Set(parent, r.FieldTo, r.FieldVo) - } -} - -func (r *Reflect) SetFieldNameByIndex(parent interface{}, fieldIndex int) { // , fieldTo reflect.StructField, fieldVo reflect.Value) { - for range Only.Once { - p := reflect.TypeOf(parent) + p := reflect.TypeOf(current) if p.Kind() == reflect.Struct { r.FieldTo = p.Field(fieldIndex) r.IsExported = r.FieldTo.IsExported() - r.FieldVo = reflect.ValueOf(parent).Field(fieldIndex) + r.FieldVo = reflect.ValueOf(current).Field(fieldIndex) r.FieldName = r.FieldTo.Name - r.DataStructure = r.DataStructure.Set(parent, r.FieldTo, r.FieldVo) + r.DataStructure = r.DataStructure.Set(parent, current, r.FieldTo, r.FieldVo) break } if p.Kind() == reflect.Array { r.FieldTo = p.Field(fieldIndex) r.IsExported = r.FieldTo.IsExported() - r.FieldVo = reflect.ValueOf(parent).Field(fieldIndex) + r.FieldVo = reflect.ValueOf(current).Field(fieldIndex) r.FieldName = r.FieldTo.Name - r.DataStructure = r.DataStructure.Set(parent, r.FieldTo, r.FieldVo) + r.DataStructure = r.DataStructure.Set(parent, current, r.FieldTo, r.FieldVo) break } } } // setPointName - Are we using an index number for name or field key value? -func (r *Reflect) setPointName(parentRef interface{}, childRef interface{}, name []string, index int) []string { +func (r *Reflect) setPointName(parent interface{}, current interface{}, name []string, index int) []string { for range Only.Once { // pointTimestamp := time.Now() // pointTimestampFrom := fieldTo.Tag.Get(PointTimestampFrom) @@ -222,7 +228,7 @@ func (r *Reflect) setPointName(parentRef interface{}, childRef interface{}, name switch { case r.DataStructure.PointNameFromChild != "": // PointNameFromChild - In this case points to a field within a CHILD struct. - pn = GetPointNameFrom(childRef, r.DataStructure.PointNameFromChild, intSize, r.DataStructure.PointNameDateFormat) + pn = GetPointNameFrom(current, r.DataStructure.PointNameFromChild, intSize, r.DataStructure.PointNameDateFormat) if r.DataStructure.PointNameFromAppend == "true" { name = append(name, pn) } else { @@ -231,7 +237,7 @@ func (r *Reflect) setPointName(parentRef interface{}, childRef interface{}, name case r.DataStructure.PointNameFromParent != "": // PointNameFromChild - In this case points to a field within a CHILD struct. - pn = GetPointNameFrom(parentRef, r.DataStructure.PointNameFromParent, intSize, r.DataStructure.PointNameDateFormat) + pn = GetPointNameFrom(parent, r.DataStructure.PointNameFromParent, intSize, r.DataStructure.PointNameDateFormat) if r.DataStructure.PointNameFromAppend == "true" { name = append(name, pn) } else { @@ -248,44 +254,53 @@ func (r *Reflect) setPointName(parentRef interface{}, childRef interface{}, name type DataStructure struct { - // PointType string + Required bool Json string PointId string PointParentId string - PointUnit string - PointUnitFrom string - PointTimestamp time.Time - PointName string PointUpdateFreq string PointValueType string PointAliasTo string - PointIgnore bool - PointIgnoreIfNil string - PointIgnoreIfNilFromChild string - PointGroupName string - PointGroupNameFrom string + + PointTimestamp time.Time PointTimestampFrom string - PointArrayFlatten string - PointIgnoreZero bool + + PointUnit string + PointUnitFrom string + PointUnitFromParent string + + PointName string PointNameFromAppend string PointNameFromChild string PointNameFromParent string PointNameDateFormat string - Value interface{} - ValueType string - ValueKind string - Endpoint string + PointIgnore bool + PointIgnoreZero bool + PointIgnoreIfNil string + PointIgnoreIfNilFromChild string + + PointGroupName string + PointGroupNameFrom string + + PointArrayFlatten string + PointSplitOn string + PointSplitOnType string + + Value interface{} + ValueType string + ValueKind string + Endpoint string } -func (ds *DataStructure) Set(parentRef interface{}, fieldTo reflect.StructField, fieldVo reflect.Value) DataStructure { +func (ds *DataStructure) Set(parent interface{}, current interface{}, fieldTo reflect.StructField, fieldVo reflect.Value) DataStructure { for range Only.Once { - // sf, ok := reflect.TypeOf(parentRef).FieldByName(fieldName) + // sf, ok := reflect.TypeOf(current).FieldByName(fieldName) // if !ok { // break // } // fieldTo := sf - // fieldVo := reflect.ValueOf(parentRef).FieldByName(fieldName) + // fieldVo := reflect.ValueOf(current).FieldByName(fieldName) ignore := false if fieldTo.Tag.Get(PointIgnore) != "" { @@ -294,7 +309,7 @@ func (ds *DataStructure) Set(parentRef interface{}, fieldTo reflect.StructField, pointIgnoreIfNil := fieldTo.Tag.Get(PointIgnoreIfNil) if pointIgnoreIfNil != "" { - ret := GetStringFrom(parentRef, pointIgnoreIfNil) + ret := GetStringFrom(current, pointIgnoreIfNil) if (ret == "") || (ret == "--") { ignore = true } @@ -330,20 +345,24 @@ func (ds *DataStructure) Set(parentRef interface{}, fieldTo reflect.StructField, pointUnit := fieldTo.Tag.Get(PointUnit) pointUnitFrom := fieldTo.Tag.Get(PointUnitFrom) + pointUnitFromParent := fieldTo.Tag.Get(PointUnitFromParent) if pointUnitFrom != "" { - pointUnit = GetStringFrom(parentRef, pointUnitFrom) + pointUnit = GetStringFrom(current, pointUnitFrom) + } + if pointUnitFromParent != "" { + pointUnit = GetStringFrom(parent, pointUnitFromParent) } pointGroupName := fieldTo.Tag.Get(PointGroupName) pointGroupNameFrom := fieldTo.Tag.Get(PointGroupNameFrom) if pointGroupNameFrom != "" { - pointGroupName = GetStringFrom(parentRef, pointGroupNameFrom) + pointGroupName = GetStringFrom(current, pointGroupNameFrom) } pointTimestamp := time.Now() pointTimestampFrom := fieldTo.Tag.Get(PointTimestampFrom) if pointTimestampFrom != "" { - pointTimestamp = GetTimestampFrom(parentRef, pointTimestampFrom, valueTypes.DateTimeLayout) + pointTimestamp = GetTimestampFrom(current, pointTimestampFrom, valueTypes.DateTimeLayout) } var valueType string @@ -379,13 +398,21 @@ func (ds *DataStructure) Set(parentRef interface{}, fieldTo reflect.StructField, pointUpdateFreq = UpdateFreqTotal } + var required bool + req := fieldTo.Tag.Get("required") + if req == "true" { + required = true + } + *ds = DataStructure { + Required: required, Json: pointJson, PointId: pointId, PointParentId: fieldTo.Tag.Get(PointParentId), - PointUnit: pointUnit, - PointUnitFrom: pointUnitFrom, + PointUnit: pointUnit, + PointUnitFrom: pointUnitFrom, + PointUnitFromParent: pointUnitFromParent, PointTimestamp: pointTimestamp, PointTimestampFrom: pointTimestampFrom, @@ -406,6 +433,8 @@ func (ds *DataStructure) Set(parentRef interface{}, fieldTo reflect.StructField, PointIgnoreIfNil: pointIgnoreIfNil, PointIgnoreIfNilFromChild: fieldTo.Tag.Get(PointIgnoreIfNilFromChild), PointArrayFlatten: fieldTo.Tag.Get(PointArrayFlatten), + PointSplitOn: fieldTo.Tag.Get(PointSplitOn), + PointSplitOnType: fieldTo.Tag.Get(PointSplitOnType), PointIgnoreZero: pointIgnoreZero, Value: nil, @@ -512,7 +541,7 @@ func (dss *DataStructures) GetPointTags(Parent Reflect, Current Reflect, name .. // @TODO - Need to cover types other than struct that may be referenced. var Child Reflect - Child.SetByIndex(Current.Interface, si) + Child.SetByIndex(Parent.Interface, Current.Interface, si) name3 := Current.setPointName(Parent.Interface, Child.Interface, name, si) dss.GetPointTags(Current, Child, name3...) } @@ -554,7 +583,7 @@ func (dss *DataStructures) GetPointTags(Parent Reflect, Current Reflect, name .. // @TODO - Need to cover types other than struct that may be referenced. var Child Reflect - Child.SetByIndex(Current.Interface, si) + Child.SetByIndex(Parent.Interface, Current.Interface, si) name3 := Current.setPointName(Parent.Interface, Child.Interface, name, si) dss.GetPointTags(Current, Child, name3...) } @@ -582,7 +611,7 @@ func (dss *DataStructures) GetPointTags(Parent Reflect, Current Reflect, name .. } } - Parent.SetByFieldName(Parent.Interface, Current.Interface, "") + // Parent.SetByFieldName(Parent.Interface, Current.Interface, "") // n2 := append(name, Current.DataStructure.PointId) for _, key := range Current.FieldVo.MapKeys() { // @TODO - Implement pointNameFromChild / pointNameFromParent. @@ -591,17 +620,26 @@ func (dss *DataStructures) GetPointTags(Parent Reflect, Current Reflect, name .. val := Current.FieldVo.MapIndex(key) Current.DataStructure.Value = val.Interface() Current.DataStructure.Endpoint = strings.Join(name, ".") + "." + Current.DataStructure.PointId - // @TODO - For integers, it'd be nice to format them with a 0 prefix. // ft := valueTypes.GetIntFormatForPrintf(r.Length) // pn := fmt.Sprintf(ft, index) // intSize := valueTypes.SizeOfInt(r.Length) // name3 := Current.setPointName(Parent.Interface, Current.Interface, name, si) // fmt.Printf("DEBUG: %s / %s\n", Current.DataStructure.Endpoint, name3) - // @TODO - Need to look at other types, besides known types. - dss.Add(Current.DataStructure) + + if Current.DataStructure.PointSplitOn != "" { + // We want to split a string into separate points - currently only handles string types. + // @TODO - Fix this up! - Use PointSplitOnType + soEP := Current.DataStructure.Endpoint + soVal := valueTypes.AnyToValueString(Current.FieldVo.Interface(), 0, "") + for soI, soV := range strings.Split(soVal, Current.DataStructure.PointSplitOn) { + Current.DataStructure.Value = soV + Current.DataStructure.Endpoint = fmt.Sprintf("%s.%d", soEP, soI) + dss.Add(Current.DataStructure) + } + } } break } @@ -620,11 +658,11 @@ func (dss *DataStructures) GetPointTags(Parent Reflect, Current Reflect, name .. } } - Parent.SetByFieldName(Parent.Interface, Current.Interface, "") + // Parent.SetByFieldName(Parent.Interface, Current.Interface, "") // Iterate over all available fields and read the tag value for i := 0; i < Current.Length; i++ { var Child Reflect - Child.SetByIndex(Current.Interface, i) + Child.SetByIndex(Current.Parent, Current.Interface, i) name2 := append(name, Child.DataStructure.PointId) if !Child.IsExported { @@ -649,6 +687,18 @@ func (dss *DataStructures) GetPointTags(Parent Reflect, Current Reflect, name .. Child.DataStructure.Value = Child.Interface Child.DataStructure.Endpoint = strings.Join(name, ".") + "." + Child.DataStructure.PointId dss.Add(Child.DataStructure) + + if Child.DataStructure.PointSplitOn != "" { + // We want to split a string into separate points - currently only handles string types. + // @TODO - Fix this up! - Use PointSplitOnType + soEP := Child.DataStructure.Endpoint + soVal := valueTypes.AnyToValueString(Child.FieldVo.Interface(), 0, "") + for soI, soV := range strings.Split(soVal, Child.DataStructure.PointSplitOn) { + Child.DataStructure.Value = soV + Child.DataStructure.Endpoint = fmt.Sprintf("%s.%d", soEP, soI) + dss.Add(Child.DataStructure) + } + } continue } @@ -673,7 +723,6 @@ func (dss *DataStructures) GetPointTags(Parent Reflect, Current Reflect, name .. fallthrough case reflect.UnsafePointer: dss.GetPointTags(Current, Child, name2...) - continue default: // @TODO - Need to fix this! @@ -681,6 +730,18 @@ func (dss *DataStructures) GetPointTags(Parent Reflect, Current Reflect, name .. Child.DataStructure.Value = Child.Interface Child.DataStructure.Endpoint = strings.Join(name, ".") + "." + Child.DataStructure.PointId dss.Add(Child.DataStructure) + + if Child.DataStructure.PointSplitOn != "" { + // We want to split a string into separate points - currently only handles string types. + // @TODO - Fix this up! - Use PointSplitOnType + soEP := Current.DataStructure.Endpoint + soVal := valueTypes.AnyToValueString(Child.FieldVo.Interface(), 0, "") + for soI, soV := range strings.Split(soVal, Child.DataStructure.PointSplitOn) { + Child.DataStructure.Value = soV + Child.DataStructure.Endpoint = fmt.Sprintf("%s.%d", soEP, soI) + dss.Add(Child.DataStructure) + } + } } } break @@ -710,14 +771,14 @@ func GetStructFields(ref interface{}) map[string]string { // Iterate over all available fields and read the tag value for i := 0; i < Ref.Length; i++ { var Child Reflect - Child.SetByIndex(Ref.Interface, i) + Child.SetByIndex(Ref.Interface, Ref.Interface, i) // SetFieldNameByIndex if !Child.IsExported { continue } - ret[Child.FieldName] = Child.DataStructure.Json + ret[Child.FieldName] = fmt.Sprintf("%v", Child.DataStructure.Required) } break } @@ -726,6 +787,70 @@ func GetStructFields(ref interface{}) map[string]string { return ret } +func GetStructFieldsAsArray(ref interface{}) []string { + var ret []string + + for range Only.Once { + var Ref Reflect + Ref.SetByFieldName(ref, ref, "") + + if Ref.Kind == reflect.Struct { + if Ref.Length == 0 { + if Ref.DataStructure.PointIgnoreZero { + break + } + } + + // Iterate over all available fields and read the tag value + for i := 0; i < Ref.Length; i++ { + var Child Reflect + Child.SetByIndex(Ref.Interface, Ref.Interface, i) + // SetFieldNameByIndex + + if !Child.IsExported { + continue + } + + ret = append(ret, Child.FieldName) + } + } + } + + return ret +} + +func GetStructValuesAsArray(ref interface{}) []string { + var ret []string + + for range Only.Once { + var Ref Reflect + Ref.SetByFieldName(ref, ref, "") + + if Ref.Kind == reflect.Struct { + if Ref.Length == 0 { + if Ref.DataStructure.PointIgnoreZero { + break + } + } + + // Iterate over all available fields and read the tag value + for i := 0; i < Ref.Length; i++ { + var Child Reflect + Child.SetByIndex(Ref.Interface, Ref.Interface, i) + // SetFieldNameByIndex + + if !Child.IsExported { + continue + } + + ret = append(ret, fmt.Sprintf("%v", Child.Interface)) + } + } + } + + return ret +} + func GetStringFrom(ref interface{}, name string) string { var ret string for range Only.Once { @@ -803,7 +928,8 @@ func GetPointNameFrom(ref interface{}, name string, intSize int, dateFormat stri for _, pnf := range strings.Split(name, ".") { // Iterate over all available fields, looking for the field name. for i := 0; i < vo.NumField(); i++ { - if vo.Type().Field(i).Name == pnf { + fn := vo.Type().Field(i).Name + if fn == pnf { ra = append(ra, valueTypes.AnyToValueString(vo.Field(i).Interface(), intSize, dateFormat)) break } @@ -812,7 +938,7 @@ func GetPointNameFrom(ref interface{}, name string, intSize int, dateFormat stri case reflect.Map: for _, pnf := range strings.Split(name, ".") { - // Iterate over all available fields, looking for the field name. + // Iterate over all available keys, looking for the key name. for _, key := range vo.MapKeys() { if key.String() == pnf { ra = append(ra, valueTypes.AnyToValueString(vo.MapIndex(key).Interface(), intSize, dateFormat)) @@ -1305,6 +1431,7 @@ func VerifyOptionsRequired(ref interface{}) error { var err error for range Only.Once { + // @TODO - Move over to using Reflect structure. // required := GetOptionsRequired(ref) vo := reflect.ValueOf(ref) diff --git a/iSolarCloud/api/file.go b/iSolarCloud/api/file.go index 0798ab384..4690a3865 100644 --- a/iSolarCloud/api/file.go +++ b/iSolarCloud/api/file.go @@ -9,9 +9,23 @@ import ( "github.com/MickMake/GoUnify/cmdPath" "os" "path/filepath" + "strings" ) +func (ep *EndPointStruct) ApiSetFilenamePrefix2(ref interface{}, format string, args ...interface{}) string { + f := strings.Join(apiReflect.GetStructValuesAsArray(ref), "-") + fmt.Printf("[%s]\n", f) + if format != "" { + ep.FileNamePrefix = fmt.Sprintf(format, args...) + // ep.FileNamePrefix = fmt.Sprintf("%s_%s-%s", ep.Area, ep.Name, ep.FileNamePrefix) + ep.FileNamePrefix = string(ep.Area) + "_" + string(ep.Name) + "-" + ep.FileNamePrefix + } else { + ep.FileNamePrefix = string(ep.Area) + "_" + string(ep.Name) + } + return ep.FileNamePrefix +} + func (ep *EndPointStruct) ApiSetFilenamePrefix(format string, args ...interface{}) string { if format != "" { ep.FileNamePrefix = fmt.Sprintf(format, args...) diff --git a/iSolarCloud/api/nullEndpoint/data.go b/iSolarCloud/api/nullEndpoint/data.go deleted file mode 100644 index 06e538177..000000000 --- a/iSolarCloud/api/nullEndpoint/data.go +++ /dev/null @@ -1,76 +0,0 @@ -package nullEndpoint - -import ( - "GoSungrow/iSolarCloud/api" - "GoSungrow/iSolarCloud/api/apiReflect" - "GoSungrow/iSolarCloud/api/valueTypes" - "errors" - "fmt" - "github.com/MickMake/GoUnify/Only" -) - - -const Url = "%URL%" -const Disabled = true - -type RequestData struct { - // DeviceType string `json:"device_type" required:"true"` -} - -// IsValid Checks for validity of results data. -func (rd RequestData) IsValid() error { - return apiReflect.VerifyOptionsRequired(rd) -} - -// Help provides more info to the user on request JSON fields. -func (rd RequestData) Help() string { - ret := fmt.Sprintf("") - return ret -} - -// ResultData holds data returned from the API. -type ResultData struct { - Dummy string `json:"dummy"` -} - -// IsValid Checks for validity of results data. -func (e *ResultData) IsValid() error { - var err error - switch { - case e.Dummy == "": - break - default: - err = errors.New(fmt.Sprintf("unknown error '%s'", e.Dummy)) - } - return err -} - -// type DecodeResultData ResultData -// -// func (e *ResultData) UnmarshalJSON(data []byte) error { -// var err error -// -// for range Only.Once { -// if len(data) == 0 { -// break -// } -// var pd DecodeResultData -// -// // Store ResultData -// _ = json.Unmarshal(data, &pd) -// e.Dummy = pd.Dummy -// } -// -// return err -// } - - -func (e *EndPoint) GetData() api.DataMap { - entries := api.NewDataMap() - - for range Only.Once { - entries.StructToPoints(e.Response.ResultData, apiReflect.GetName("", *e), "system", valueTypes.NewDateTime("")) - } - - return entries -} diff --git a/iSolarCloud/api/nullEndpoint/struct.go b/iSolarCloud/api/nullEndpoint/struct.go deleted file mode 100644 index a60bffa13..000000000 --- a/iSolarCloud/api/nullEndpoint/struct.go +++ /dev/null @@ -1,434 +0,0 @@ -// Package nullEndpoint -// - This file is auto-generated from the update_all.sh script. -// Do not modify anything here. Any changes to this EndPoint should be made in the data.go file. -// The only exception is the AppService.login package. -package nullEndpoint - -import ( - "GoSungrow/Only" - "GoSungrow/iSolarCloud/api" - "GoSungrow/iSolarCloud/api/apiReflect" - "GoSungrow/iSolarCloud/api/output" - "encoding/json" - "errors" - "fmt" - "sort" - "time" -) - - -// api.EndPoint - Import API endpoint interface -var _ api.EndPoint = (*EndPoint)(nil) - -// EndPoint - Holds the request, response and web method structures. -type EndPoint struct { - api.EndPointStruct - Request Request - Response Response - RawResponse []byte -} - -// Request - Holds the api.RequestCommon and user RequestData structures. See data.go for request fields. -type Request struct { - api.RequestCommon - RequestData -} - -// Response - Holds the api.ResponseCommon and endpoint specific ResultData structures. See data.go for response fields. -type Response struct { - api.ResponseCommon - ResultData ResultData `json:"result_data"` -} - -// Init - Used to initialize a new endpoint instance. Usually called from an area. -func Init(apiRoot api.Web) EndPoint { - return EndPoint{ - EndPointStruct: api.EndPointStruct{ - ApiRoot: apiRoot, - Area: api.GetArea(EndPoint{}), - Name: api.GetName(EndPoint{}), - Url: api.SetUrl(Url), - Request: Request{}, - Response: Response{}, - Error: nil, - }, - } -} - - -// ******************************************************************************** // - -// Methods not scoped by api.EndPoint interface type - -// Init - If the endpoint needs to be re-initialized. -func (e EndPoint) Init(apiRoot api.Web) *EndPoint { - ret := Init(apiRoot) - return &ret -} - -// GetRequest - Get the Request structure as scoped by this endpoint. -func (e EndPoint) GetRequest() Request { - return e.Request -} - -// GetResponse - Get the Response structure as scoped by this endpoint. -func (e EndPoint) GetResponse() Response { - return e.Response -} - -// Assert - Used to obtain locally scoped EndPoint methods, (not visible from api.EndPoint). -//goland:noinspection GoUnusedExportedFunction -func Assert(e api.EndPoint) EndPoint { - return e.(EndPoint) -} - -// AssertResultData - Used to obtain locally scoped ResultData methods, (not visible from api.EndPoint). -//goland:noinspection GoUnusedExportedFunction -func AssertResultData(e api.EndPoint) ResultData { - return e.(EndPoint).Response.ResultData -} - - -// ******************************************************************************** // - -// Methods defined by api.EndPoint interface type - -// Help - Return help information on the JSON structure used to populate RequestData. -func (e EndPoint) Help() string { - ret := apiReflect.HelpOptions(e.Request.RequestData) - ret += fmt.Sprintf("JSON request:\t%s\n", e.GetRequestJson()) - ret += e.Request.Help() - return ret -} - -// IsDisabled - Is this endpoint disabled? See data.go Disabled constant. -func (e EndPoint) IsDisabled() bool { - return Disabled -} - -// GetArea - Returns the API area that this EndPoint is located. -func (e EndPoint) GetArea() api.AreaName { - return e.Area -} - -// GetName - Returns the API EndPoint name. -func (e EndPoint) GetName() api.EndPointName { - return e.Name -} - -// GetUrl - Returns the API EndPoint url. -func (e EndPoint) GetUrl() api.EndPointUrl { - return e.Url -} - -// Call - Once RequestData is populated, this will access the iSolarCloud API and populate ResultData. -func (e EndPoint) Call() api.EndPoint { - return e.ApiRoot.Get(e) -} - -// GetJsonData - Get the JSON representation of ResultData, either as condensed or "pretty". -func (e EndPoint) GetJsonData(raw bool) output.Json { - if raw { - // return output.GetAsPrettyJson(string(e.RawResponse)) - return output.Json(e.RawResponse) - } else { - return output.GetAsPrettyJson(e.Response.ResultData) - } -} - -// SetError - Set the error code for this EndPoint. -func (e EndPoint) SetError(format string, a ...interface{}) api.EndPoint { - e.EndPointStruct.Error = errors.New(fmt.Sprintf(format, a...)) - return e -} - -// GetError - Get the error code for this EndPoint. -func (e EndPoint) GetError() error { - return e.EndPointStruct.Error -} - -// IsError - Is there an error? -func (e EndPoint) IsError() bool { - if e.Error != nil { - return true - } - return false -} - -// ReadDataFile - Read a JSON file and populate the ResultData structure. -// (File names will default to AREA-ENDPOINT.json ) -func (e EndPoint) ReadDataFile() error { - // return e.FileRead("", &e.Response.ResultData) - return e.ApiReadDataFile(&e.Response.ResultData) -} - -// WriteDataFile - Write to a file, the contents of ResultData as JSON. -// (File names will default to AREA-ENDPOINT.json ) -func (e EndPoint) WriteDataFile() error { - // return e.FileWrite("", e.Response.ResultData, output.DefaultFileMode) - return e.ApiWriteDataFile(e.Response.ResultData) -} - - -// ******************************************************************************** - -// SetRequest - Save an interface reference as either api.RequestCommon or RequestData. -func (e EndPoint) SetRequest(ref interface{}) api.EndPoint { - for range Only.Once { - if apiReflect.GetPkgType(ref) == "api.RequestCommon" { - e.Request.RequestCommon = ref.(api.RequestCommon) - break - } - - if apiReflect.GetType(ref) == "RequestData" { - e.Request.RequestData = ref.(RequestData) - e.Error = e.IsRequestValid() - break - } - - e.Error = apiReflect.DoPkgTypesMatch(e.Request, ref) - if e.Error != nil { - break - } - - e.Request = ref.(Request) - } - return e -} - -// SetRequestByJson - Save RequestData from a JSON string. -func (e EndPoint) SetRequestByJson(j output.Json) api.EndPoint { - for range Only.Once { - e.Error = json.Unmarshal([]byte(j), &e.Request.RequestData) - if e.Error != nil { - break - } - e.Error = e.IsRequestValid() - if e.Error != nil { - break - } - } - return e -} - -// RequestRef - Return the locally scoped Request structure. -func (e EndPoint) RequestRef() interface{} { - return e.Request -} - -// GetRequestJson - Return the Request structure as a JSON string. -func (e EndPoint) GetRequestJson() output.Json { - return output.GetAsJson(e.Request.RequestData) -} - -// // GetFingerprint - Used to formulate cache filenames. -// func (e EndPoint) GetFingerprint() string { -// return apiReflect.GetFingerprint(e.Request.RequestData) -// } - -// IsRequestValid - Is api.RequestCommon and RequestData valid? -func (e EndPoint) IsRequestValid() error { - for range Only.Once { - // req := e.GetRequest() - // req := e.Request.RequestCommon - e.Error = e.Request.RequestCommon.IsValid() - if e.Error != nil { - break - } - e.Error = e.Request.RequestData.IsValid() - if e.Error != nil { - break - } - } - return e.Error -} - - -// ******************************************************************************** - -// SetResponse - Save a JSON string to the Response structure. -// (Used by the web call method.) -func (e EndPoint) SetResponse(ref []byte) api.EndPoint { - for range Only.Once { - e.RawResponse = ref - e.Error = json.Unmarshal(ref, &e.Response) - if e.Error != nil { - break - } - } - return e -} - -// GetResponseJson - Return the Response structure as a JSON string. -func (e EndPoint) GetResponseJson() output.Json { - return output.GetAsPrettyJson(e.Response) -} - -// ResponseRef - Return the locally scoped Response structure. -func (e EndPoint) ResponseRef() interface{} { - return e.Response -} - -// IsResponseValid - Is api.ResponseCommon and ResultData valid? -func (e EndPoint) IsResponseValid() error { - for range Only.Once { - e.Error = e.Response.ResponseCommon.IsValid() - if e.Error != nil { - break - } - e.Error = e.Response.ResultData.IsValid() - if e.Error != nil { - break - } - } - return e.Error -} - -// String - Stringer method for this EndPoint. -func (e EndPoint) String() string { - return output.GetEndPointString(e) -} - -// RequestString - Return the Request structure as a human-readable string. -func (e EndPoint) RequestString() string { - return output.GetRequestString(e.Request) -} - -// ResponseString - Return the Response structure as a human-readable string. -func (e EndPoint) ResponseString() string { - return output.GetRequestString(e.Response) -} - - -// ******************************************************************************** - -// MarshalJSON - Marshall the EndPoint. -func (e EndPoint) MarshalJSON() ([]byte, error) { - return api.MarshalJSON(e) - - // return json.Marshal(&struct { - // Area string `json:"area"` - // EndPoint string `json:"endpoint"` - // Host string `json:"api_host"` - // Url string `json:"endpoint_url"` - // Request interface{} `json:"request"` - // Response interface{} `json:"response"` - // }{ - // Area: string(e.Area), - // EndPoint: string(e.Name), - // Host: e.ApiRoot.Url.String(), - // Url: e.Url.String(), - // Request: e.Request, - // Response: e.Response, - // }) -} - - -// ******************************************************************************** - -// RequestFingerprint - Check if a cache file exists for this EndPoint. -func (e EndPoint) RequestFingerprint() string { - return e.ApiFingerprint(e.Request.RequestData) -} - -// CacheFilename - Check if a cache file exists for this EndPoint. -func (e EndPoint) CacheFilename() string { - return e.ApiCacheFilename(e.Request.RequestData) -} - -// // CheckCache - Check if a cache file exists for this EndPoint. -// func (e EndPoint) CheckCache() bool { -// return e.ApiCheckCache(e.Request.RequestData) -// } -// -// // ReadCache - Read a cache file and return it as an EndPoint structure. -// func (e EndPoint) ReadCache() api.EndPoint { -// e.Error = e.ApiReadCache(e.Request.RequestData, &e) -// return e -// } -// -// // WriteCache - Write this EndPoint structure out to a cache file. -// func (e EndPoint) WriteCache() error { -// return e.ApiWriteCache(e.Request.RequestData, e) -// } - -// SetCacheTimeout - Set the cache timeout for this EndPoint. (Defaults to 1 hour.) -func (e EndPoint) SetCacheTimeout(duration time.Duration) api.EndPoint { - e.ApiRoot.SetCacheTimeout(duration) - return e -} - -// GetCacheTimeout - Return the cache timeout for this EndPoint. -func (e EndPoint) GetCacheTimeout() time.Duration { - return e.ApiRoot.GetCacheTimeout() -} - -func (e EndPoint) GetDataTable() output.Table { - var table output.Table - for range Only.Once { - table = output.NewTable() - table.SetTitle("") - table.SetJson([]byte(e.GetJsonData(false))) - table.SetRaw([]byte(e.GetJsonData(true))) - - _ = table.SetHeader( - "Date", - "Point Id", - "Value", - "Unit", - "Group Name", - "Description", - ) - - data := e.GetData() - var sorted []string - for p := range data.Map { - sorted = append(sorted, string(p)) - } - sort.Strings(sorted) - - for _, p := range sorted { - entries := data.Map[api.PointId(p)] - for _, de := range entries { - if de.Hide { - continue - } - - _ = table.AddRow( - de.Date.Format(api.DtLayout), - // api.NameDevicePointInt(de.Point.Parents, p.PointID.Value()), - // de.Point.Id, - p, - // de.Point.Parents.String(), - de.Value, - de.Point.Unit, - de.Point.GroupName, - de.Point.Name, - ) - } - } - - // table.InitGraph(output.GraphRequest { - // Title: "", - // TimeColumn: output.SetInteger(1), - // SearchColumn: output.SetInteger(2), - // NameColumn: output.SetInteger(4), - // ValueColumn: output.SetInteger(5), - // UnitsColumn: output.SetInteger(6), - // SearchString: output.SetString(""), - // MinLeftAxis: output.SetFloat(0), - // MaxLeftAxis: output.SetFloat(0), - // }) - } - return table -} - -// SetFilenamePrefix - Produce filename based on area and endpoint name. -func (e EndPoint) SetFilenamePrefix(format string, args ...interface{}) string { - return e.ApiSetFilenamePrefix(format, args...) -} - -// GetRequestArgNames - -func (e EndPoint) GetRequestArgNames() map[string]string { - return e.ApiGetRequestArgNames(e.Request.RequestData) -} diff --git a/iSolarCloud/api/output/struct_output.go b/iSolarCloud/api/output/struct_output.go index 51068d8c7..7381ce241 100644 --- a/iSolarCloud/api/output/struct_output.go +++ b/iSolarCloud/api/output/struct_output.go @@ -1,5 +1,8 @@ package output +import ( + "github.com/MickMake/GoUnify/Only" +) const ( TypeNone = iota @@ -132,18 +135,28 @@ func (out *OutputType) IsStrGraph(t string) bool { func (out *OutputType) Set(outputType string) { - switch outputType { - case StringTypeJson: - out.SetJson() - case StringTypeCsv: - out.SetCsv() - case StringTypeRaw: - out.SetRaw() - case StringTypeGraph: - out.SetGraph() - case StringTypeTable: - fallthrough - default: - out.SetTable() + for range Only.Once { + // re := regexp.MustCompile(`^(\w+)\s`) + // ot := re.FindStringSubmatch(outputType) + // if len(ot) == 0 { + // break + // } + // fmt.Printf("%s\n", ot[0]) + // + // switch strings.ToLower(ot[0]) { + switch outputType { + case StringTypeJson: + out.SetJson() + case StringTypeCsv: + out.SetCsv() + case StringTypeRaw: + out.SetRaw() + case StringTypeGraph: + out.SetGraph() + case StringTypeTable: + fallthrough + default: + out.SetTable() + } } } diff --git a/iSolarCloud/api/output/struct_table.go b/iSolarCloud/api/output/struct_table.go index f43a09c3b..6631593dc 100644 --- a/iSolarCloud/api/output/struct_table.go +++ b/iSolarCloud/api/output/struct_table.go @@ -69,6 +69,10 @@ func (t *Table) SetRaw(data []byte) { t.raw = data } +func (t *Table) AppendRaw(data []byte) { + t.raw = append(t.raw, data...) +} + func (t *Table) SetJson(data []byte) { t.json = data } @@ -130,6 +134,43 @@ func (t *Table) Output() error { if t == nil { break } + + // switch { + // case sg.OutputType.IsNone(): + // if sg.Error != nil { + // fmt.Println(ret.Help()) + // break + // } + // + // case sg.OutputType.IsRaw(): + // // if sg.Error != nil { + // // fmt.Println(ret.Help()) + // // break + // // } + // if sg.SaveAsFile { + // sg.Error = ret.WriteDataFile() + // break + // } + // fmt.Println(ret.GetJsonData(true)) + // + // case sg.OutputType.IsJson(): + // if sg.Error != nil { + // fmt.Println(ret.Help()) + // break + // } + // if sg.SaveAsFile { + // sg.Error = ret.WriteDataFile() + // break + // } + // fmt.Println(ret.GetJsonData(false)) + // + // default: + // if sg.Error != nil { + // fmt.Println(ret.Help()) + // break + // } + // } + switch { case t.OutputType.IsNone(): @@ -240,6 +281,10 @@ func (t *Table) GetRaw() string { return string(t.json) } +func (t *Table) GetRawBytes() []byte { + return t.json +} + func (t *Table) WriteRaw() error { if t.saveAsFile { return t.writeFile(t.filePrefix+".raw", string(t.raw), DefaultFileMode) diff --git a/iSolarCloud/api/struct_data.go b/iSolarCloud/api/struct_data.go index 326a54e8b..81130c875 100644 --- a/iSolarCloud/api/struct_data.go +++ b/iSolarCloud/api/struct_data.go @@ -42,6 +42,8 @@ func (dm *DataMap) StructToPoints(ref interface{}, endpoint string, parentId str endpoint = apiReflect.GetCallerPackage(2) } + now := valueTypes.SetDateTimeValue(time.Now().Round(5 * time.Minute)) + // Iterate over all available fields and read the tag values var tp apiReflect.DataStructures var Ref apiReflect.Reflect @@ -71,31 +73,14 @@ func (dm *DataMap) StructToPoints(ref interface{}, endpoint string, parentId str continue } - // switch f.PointUpdateFreq { - // case "UpdateFreqInstant": - // f.PointUpdateFreq = UpdateFreqInstant - // case "UpdateFreq5Mins": - // f.PointUpdateFreq = UpdateFreq5Mins - // case "UpdateFreqBoot": - // f.PointUpdateFreq = UpdateFreqBoot - // case "UpdateFreqDay": - // f.PointUpdateFreq = UpdateFreqDay - // case "UpdateFreqMonth": - // f.PointUpdateFreq = UpdateFreqMonth - // case "UpdateFreqYear": - // f.PointUpdateFreq = UpdateFreqYear - // case "UpdateFreqTotal": - // f.PointUpdateFreq = UpdateFreqTotal - // } - var when valueTypes.DateTime if !f.PointTimestamp.IsZero() { - dt := valueTypes.SetDateTimeValue(f.PointTimestamp) - when = *dt + // dt := valueTypes.SetDateTimeValue(f.PointTimestamp) + when = valueTypes.SetDateTimeValue(f.PointTimestamp) } else { if timestamp.IsZero() { - dt := valueTypes.SetDateTimeValue(time.Now().Round(5 * time.Minute)) - when = *dt + // dt := valueTypes.SetDateTimeValue(time.Now().Round(5 * time.Minute)) + when = now } else { when = timestamp } @@ -149,54 +134,6 @@ func (dm *DataMap) AddPointUnitValue(endpoint string, parentId string, point Poi } } -func CreatePointDataEntry(endpoint string, parentId string, point Point, dateTime valueTypes.DateTime, uv valueTypes.UnitValue) DataEntry { - var ret DataEntry - for range Only.Once { - ret = DataEntry { - EndPoint: endpoint, - Point: &point, - Parent: NewParentDevice(parentId), - Date: dateTime, - Value: uv, - Valid: true, - Hide: false, - Index: 0, - } - } - - return ret -} - -func CreatePoint(parentId string, pid valueTypes.PointId, name string, groupName string, unit string, Type string, timeSpan string) Point { - var point Point - for range Only.Once { - if name == "" { - name = pid.PointToName() - } - - var parent ParentDevice - parent.Set(parentId) - var parents ParentDevices - parents.Add(parent) - - point = Point { - Parents: parents, - Id: pid, - GroupName: groupName, - Description: name, - Unit: unit, - UpdateFreq: timeSpan, - ValueType: Type, - Valid: true, - States: nil, - } - point.FixUnitType() - } - - return point -} - - func (dm *DataMap) CopyPoint(refEndpoint string, endpoint string, pointId string, name string) *DataEntries { var ret *DataEntries for range Only.Once { @@ -397,32 +334,6 @@ func (dm *DataMap) CreateTable() output.Table { return table } - - -func GetPercent(value float64, max float64) float64 { - if max == 0 { - return 0 - } - return (value / max) * 100 -} - -func JoinWithDots(intSize int, dateFormat string, args ...interface{}) string { - var ret string - for range Only.Once { - var a []string - for _, e := range args { - v := valueTypes.TypeToString(intSize, dateFormat, e) - if v == "" { - continue - } - a = append(a, v) - } - ret = strings.Join(a, ".") - } - return ret -} - - func (dm *DataMap) AddAny(endpoint string, parentId string, pid valueTypes.PointId, name string, groupName string, date valueTypes.DateTime, value interface{}, unit string, Type string, timeSpan string) { for range Only.Once { @@ -515,6 +426,79 @@ func (dm *DataMap) AddUnitValue(endpoint string, parentId string, pid valueTypes } } + +func CreatePointDataEntry(endpoint string, parentId string, point Point, dateTime valueTypes.DateTime, uv valueTypes.UnitValue) DataEntry { + var ret DataEntry + for range Only.Once { + ret = DataEntry { + EndPoint: endpoint, + Point: &point, + Parent: NewParentDevice(parentId), + Date: dateTime, + Value: uv, + Valid: true, + Hide: false, + Index: 0, + } + } + + return ret +} + +func CreatePoint(parentId string, pid valueTypes.PointId, name string, groupName string, unit string, Type string, timeSpan string) Point { + var point Point + for range Only.Once { + if name == "" { + name = pid.PointToName() + } + + var parent ParentDevice + parent.Set(parentId) + var parents ParentDevices + parents.Add(parent) + + point = Point { + Parents: parents, + Id: pid, + GroupName: groupName, + Description: name, + Unit: unit, + UpdateFreq: timeSpan, + ValueType: Type, + Valid: true, + States: nil, + } + point.FixUnitType() + } + + return point +} + +func GetPercent(value float64, max float64) float64 { + if max == 0 { + return 0 + } + return (value / max) * 100 +} + +func JoinWithDots(intSize int, dateFormat string, args ...interface{}) string { + var ret string + for range Only.Once { + var a []string + for _, ref := range args { + v := valueTypes.AnyToValueString(ref, intSize, dateFormat) + if v == "" { + continue + } + v = strings.Trim(v, ".") + a = append(a, v) + } + ret = strings.Join(a, ".") + } + return ret +} + + // func CreateDataEntry(endpoint string, parentId string, pid valueTypes.PointId, name string, groupName string, dateTime valueTypes.DateTime, uv valueTypes.UnitValue, timeSpan string) DataEntry { // var ret DataEntry // for range Only.Once { diff --git a/iSolarCloud/api/struct_point.go b/iSolarCloud/api/struct_point.go index 5e5386431..02f42305b 100644 --- a/iSolarCloud/api/struct_point.go +++ b/iSolarCloud/api/struct_point.go @@ -15,63 +15,16 @@ type Point struct { Id valueTypes.PointId `json:"id,omitempty"` GroupName string `json:"group_name,omitempty"` Description string `json:"description,omitempty"` - Unit string `json:"unit,omitempty"` - UpdateFreq string `json:"time_span,omitempty"` - ValueType string `json:"value_type,omitempty"` + Unit string `json:"unit,omitempty"` + UpdateFreq string `json:"time_span,omitempty"` + ValueType string `json:"value_type,omitempty"` Valid bool `json:"valid,omitempty"` States map[string]string `json:"states,omitempty"` } func (p *Point) FixUnitType() Point { - for range Only.Once { - switch p.Unit { - case "Wh": - fallthrough - case "kWh": - fallthrough - case "MWh": - p.ValueType = "Energy" - - case "kWp": - fallthrough - case "W": - fallthrough - case "kW": - fallthrough - case "MW": - p.ValueType = "Power" - - case "AUD": - p.ValueType = "Currency" - - case "kg": - p.ValueType = "Weight" - - case "mV": - fallthrough - case "V": - p.ValueType = "Voltage" - - case "A": - p.ValueType = "Current" - - case "Hz": - p.ValueType = "Frequency" - - case "kvar": - p.ValueType = "Reactive Power" - - case "kΩ": - p.ValueType = "Resistance" - - case "%": - p.ValueType = "Percent" - - case "℃": - p.ValueType = "Temperature" - } - } + p.ValueType = valueTypes.UnitValueType(p.Unit) return *p } diff --git a/iSolarCloud/api/types.go b/iSolarCloud/api/types.go index c3b397023..0edc1c8c9 100644 --- a/iSolarCloud/api/types.go +++ b/iSolarCloud/api/types.go @@ -10,15 +10,14 @@ import ( func (e *Web) GetDataTable(endpoint EndPoint) output.Table { var table output.Table for range Only.Once { - table = output.NewTable() + // table = output.NewTable() + data := endpoint.GetEndPointData() + table = data.CreateTable() table.SetTitle(fmt.Sprintf("Data Request %s.%s", endpoint.GetArea(), endpoint.GetName())) table.SetFilePrefix(fmt.Sprintf("%s_%s", endpoint.GetArea(), endpoint.GetName())) table.SetJson([]byte(endpoint.GetJsonData(false))) table.SetRaw([]byte(endpoint.GetJsonData(true))) - data := endpoint.GetEndPointData() - table = data.CreateTable() - // table.InitGraph(output.GraphRequest { // Title: "", // TimeColumn: output.SetInteger(1), diff --git a/iSolarCloud/api/valueTypes/datetime.go b/iSolarCloud/api/valueTypes/datetime.go index cf0bbda95..65e3f5cd5 100644 --- a/iSolarCloud/api/valueTypes/datetime.go +++ b/iSolarCloud/api/valueTypes/datetime.go @@ -9,6 +9,7 @@ import ( var inputDateLayout = []string{ + DateTimeFullLayout, DateTimeLayout, "2006/01/02 15:04:05", DateLayout, @@ -19,9 +20,11 @@ var inputDateLayout = []string{ DateTimeLayoutDay, DateTimeLayoutMonth, DateTimeLayoutYear, + DateTimeLayoutYear, } const ( + DateTimeFullLayout = time.RFC3339 DateTimeLayout = DateLayout + " " + TimeLayout DateTimeAltLayout = DateLayoutDay + "-" + TimeLayoutSecond DateTimeLayoutZeroSeconds = DateLayout + " " + TimeLayoutZeroSeconds @@ -63,14 +66,14 @@ func (dt *DateTime) UnmarshalJSON(data []byte) error { // Store result from string dt.Error = json.Unmarshal(data, &dt.string) if dt.Error == nil { - dt = dt.SetString(dt.string) + dt.SetString(dt.string) break } // Store result from time dt.Error = json.Unmarshal(data, &dt.Time) if dt.Error == nil { - dt = dt.SetValue(dt.Time) + dt.SetValue(dt.Time) break } @@ -96,11 +99,8 @@ func (dt DateTime) MarshalJSON() ([]byte, error) { var data []byte for range Only.Once { - // data, dt.Error = json.Marshal(dt.string) - // if dt.Error != nil { - // break - // } - data = []byte("\"" + dt.Time.Format(DateTimeLayout) + "\"") + // data = []byte("\"" + dt.Time.Format(DateTimeLayout) + "\"") + data = []byte("\"" + dt.string + "\"") } return data, dt.Error @@ -122,7 +122,7 @@ func (dt DateTime) Match(comp time.Time) bool { return false } -func (dt *DateTime) SetString(value string) *DateTime { +func (dt *DateTime) SetString(value string) DateTime { for range Only.Once { dt.string = value dt.Time = time.Time{} @@ -139,7 +139,7 @@ func (dt *DateTime) SetString(value string) *DateTime { for _, f := range inputDateLayout { dt.Time, dt.Error = time.Parse(f, value) if dt.Error == nil { - dt.string = dt.Time.Format(DateTimeLayout) + dt.string = dt.Time.Format(f) dt.SetDateType(value) break } @@ -150,10 +150,10 @@ func (dt *DateTime) SetString(value string) *DateTime { } } - return dt + return *dt } -func (dt *DateTime) SetValue(value time.Time) *DateTime { +func (dt *DateTime) SetValue(value time.Time) DateTime { for range Only.Once { dt.string = "" dt.Time = value @@ -166,7 +166,7 @@ func (dt *DateTime) SetValue(value time.Time) *DateTime { dt.DateType = "3" } - return dt + return *dt } func (dt *DateTime) SetDateType(value string) { @@ -188,12 +188,12 @@ func (dt *DateTime) SetDateType(value string) { } } -func SetDateTimeString(value string) *DateTime { +func SetDateTimeString(value string) DateTime { var t DateTime return t.SetString(value) } -func SetDateTimeValue(value time.Time) *DateTime { +func SetDateTimeValue(value time.Time) DateTime { var t DateTime return t.SetValue(value) } @@ -235,20 +235,25 @@ const Now = "now" func NewDateTime(value string) DateTime { var ret DateTime - if (value == Now) || (value == "") { - value = time.Now().Format(DateTimeLayout) - } - for _, f := range inputDateLayout { - ret.Time, ret.Error = time.Parse(f, value) - if ret.Error == nil { - ret.SetValue(ret.Time) - ret.SetDateType(value) + for range Only.Once { + if (value == Now) || (value == "") { + // value = time.Now().Format(DateTimeLayout) + ret.SetValue(time.Now()) + ret.SetDateType(ret.string) break } - } + for _, f := range inputDateLayout { + ret.Time, ret.Error = time.Parse(f, value) + if ret.Error == nil { + ret.SetValue(ret.Time) + ret.SetDateType(value) + break + } + } - if ret.Error != nil { - fmt.Printf("Error:NewDateTime DateTime(%s) - %s\n", value, ret.Error) + if ret.Error != nil { + fmt.Printf("Error:NewDateTime DateTime(%s) - %s\n", value, ret.Error) + } } return ret } diff --git a/iSolarCloud/api/valueTypes/float.go b/iSolarCloud/api/valueTypes/float.go index 1b03fb3e5..063c1324e 100644 --- a/iSolarCloud/api/valueTypes/float.go +++ b/iSolarCloud/api/valueTypes/float.go @@ -92,7 +92,9 @@ func (t *Float) SetString(value string) Float { } t.float64, t.Error = strconv.ParseFloat(t.string, 64) - if t.Error == nil { + if t.Error != nil { + // @TODO - Figure out a good way to handle fields that *could be* float, but aren't always. + t.Error = nil break } t.Valid = true diff --git a/iSolarCloud/api/valueTypes/ps_id.go b/iSolarCloud/api/valueTypes/ps_id.go new file mode 100644 index 000000000..45127385d --- /dev/null +++ b/iSolarCloud/api/valueTypes/ps_id.go @@ -0,0 +1,167 @@ +package valueTypes + +import ( + "encoding/json" + "github.com/MickMake/GoUnify/Only" + "strconv" +) + + +type PsId struct { + string `json:"string,omitempty"` + int64 `json:"integer,omitempty"` + Valid bool `json:"valid"` + Error error `json:"-"` +} + +// UnmarshalJSON - Convert JSON to value +func (t *PsId) UnmarshalJSON(data []byte) error { + for range Only.Once { + t.Valid = false + + if len(data) == 0 { + break + } + + // Store result from int + t.Error = json.Unmarshal(data, &t.int64) + if t.Error == nil { + t.SetValue(t.int64) + break + } + + // Store result from string + t.Error = json.Unmarshal(data, &t.string) + if t.Error == nil { + t.SetString(t.string) + break + } + + t.SetString(string(data)) + } + + return t.Error +} + +// MarshalJSON - Convert value to JSON +func (t PsId) MarshalJSON() ([]byte, error) { + var data []byte + for range Only.Once { + t.Valid = false + + data, t.Error = json.Marshal(t.int64) + if t.Error != nil { + break + } + t.Valid = true + // t.string = strconv.FormatInt(t.int64, 10) + } + + return data, t.Error +} + +func (t PsId) Value() int64 { + return t.int64 +} + +func (t PsId) String() string { + return t.string +} + +func (t PsId) Match(comp int64) bool { + if t.int64 == comp { + return true + } + return false +} + +func (t *PsId) SetString(value string) PsId { + for range Only.Once { + t.string = value + t.int64 = 0 + t.Valid = false + + if value == "" { + break + } + + if value == "--" { + // value = "" + break + } + + var v int + v, t.Error = strconv.Atoi(t.string) + if t.Error != nil { + break + } + t.int64 = int64(v) + t.Valid = true + } + + return *t +} + +func (t *PsId) SetValue(value int64) PsId { + for range Only.Once { + t.string = "" + t.int64 = value + t.Valid = true + t.string = strconv.FormatInt(t.int64, 10) + } + + return *t +} + + +func SetPsIdString(value string) PsId { + var t PsId + return t.SetString(value) +} + +func SetPsIdValue(value int64) PsId { + var t PsId + return t.SetValue(value) +} + +func SetPsIdStrings(values []string) PsIds { + var t PsIds + for range Only.Once { + // sgd.PsId = valueTypes.SetPsIdString(psId) + for _, psId := range values { + if psId == "" { + continue + } + t = append(t, SetPsIdString(psId)) + } + } + return t +} + +func SetPsIdValues(values []int64) PsIds { + var t PsIds + for range Only.Once { + // sgd.PsId = valueTypes.SetPsIdString(psId) + for _, psId := range values { + if psId == 0 { + continue + } + t = append(t, SetPsIdValue(psId)) + } + } + return t +} + + +type PsIds []PsId + +func (t *PsIds) Strings() []string { + var ret []string + for range Only.Once { + // sgd.PsId = valueTypes.SetPsIdString(psId) + for _, psId := range *t { + ret = append(ret, psId.String()) + } + } + return ret +} diff --git a/iSolarCloud/api/valueTypes/types.go b/iSolarCloud/api/valueTypes/types.go index 77d07bb92..6588a6bd2 100644 --- a/iSolarCloud/api/valueTypes/types.go +++ b/iSolarCloud/api/valueTypes/types.go @@ -18,6 +18,7 @@ const ( TypeInteger = "Integer" TypePointId = "PointId" TypePsKey = "PsKey" + TypePsId = "PsId" TypeString = "String" TypeTime = "Time" TypeUnitValue = "UnitValue" @@ -29,32 +30,35 @@ const ( TypeArrayInteger = "[]Integer" TypeArrayPointId = "[]PointId" TypeArrayPsKey = "[]PsKey" + TypeArrayPsId = "[]PsId" TypeArrayString = "[]String" TypeArrayTime = "[]Time" TypeArrayUnitValue = "[]UnitValue" TypeUnitValues = "UnitValues" - TypeArrayValueTypesBool = "[]valueTypes.Bool" - TypeArrayValueTypesCount = "[]valueTypes.Count" - TypeArrayValueTypesDateTime = "[]valueTypes.DateTime" - TypeArrayValueTypesFloat = "[]valueTypes.Float" - TypeArrayValueTypesInteger = "[]valueTypes.Integer" - TypeArrayValueTypesPointId = "[]valueTypes.PointId" - TypeArrayValueTypesPsKey = "[]valueTypes.PsKey" - TypeArrayValueTypesString = "[]valueTypes.String" - TypeArrayValueTypesTime = "[]valueTypes.Time" - TypeArrayValueTypesUnitValue = "[]valueTypes.UnitValue" - - TypeValueTypesBool = "valueTypes.Bool" - TypeValueTypesCount = "valueTypes.Count" - TypeValueTypesDateTime = "valueTypes.DateTime" - TypeValueTypesFloat = "valueTypes.Float" - TypeValueTypesInteger = "valueTypes.Integer" - TypeValueTypesPointId = "valueTypes.PointId" - TypeValueTypesPsKey = "valueTypes.PsKey" - TypeValueTypesString = "valueTypes.String" - TypeValueTypesTime = "valueTypes.Time" - TypeValueTypesUnitValue = "valueTypes.UnitValue" + // TypeArrayValueTypesBool = "[]valueTypes.Bool" + // TypeArrayValueTypesCount = "[]valueTypes.Count" + // TypeArrayValueTypesDateTime = "[]valueTypes.DateTime" + // TypeArrayValueTypesFloat = "[]valueTypes.Float" + // TypeArrayValueTypesInteger = "[]valueTypes.Integer" + // TypeArrayValueTypesPointId = "[]valueTypes.PointId" + // TypeArrayValueTypesPsKey = "[]valueTypes.PsKey" + // TypeArrayValuePsId = "[]valueTypes.PsId" + // TypeArrayValueTypesString = "[]valueTypes.String" + // TypeArrayValueTypesTime = "[]valueTypes.Time" + // TypeArrayValueTypesUnitValue = "[]valueTypes.UnitValue" + // + // TypeValueTypesBool = "valueTypes.Bool" + // TypeValueTypesCount = "valueTypes.Count" + // TypeValueTypesDateTime = "valueTypes.DateTime" + // TypeValueTypesFloat = "valueTypes.Float" + // TypeValueTypesInteger = "valueTypes.Integer" + // TypeValueTypesPointId = "valueTypes.PointId" + // TypeValueTypesPsKey = "valueTypes.PsKey" + // TypeValueTypesPsId = "valueTypes.PsId" + // TypeValueTypesString = "valueTypes.String" + // TypeValueTypesTime = "valueTypes.Time" + // TypeValueTypesUnitValue = "valueTypes.UnitValue" ) @@ -101,27 +105,32 @@ func IsUnknownStruct(ref interface{}) bool { } if kindy == reflect.Struct { - switch fieldVo.Type().String() { + Type := fieldVo.Type().String() + Type = strings.ReplaceAll(Type, "valueTypes.", "") + switch Type { case TypeBool: case TypeCount: case TypeDateTime: case TypeFloat: case TypeInteger: case TypePointId: + case TypePsId: case TypePsKey: case TypeString: case TypeTime: case TypeUnitValue: - case TypeValueTypesBool: - case TypeValueTypesCount: - case TypeValueTypesDateTime: - case TypeValueTypesFloat: - case TypeValueTypesInteger: - case TypeValueTypesPointId: - case TypeValueTypesPsKey: - case TypeValueTypesString: - case TypeValueTypesTime: - case TypeValueTypesUnitValue: + case TypeArrayBool: + case TypeArrayCount: + case TypeArrayDateTime: + case TypeArrayFloat: + case TypeArrayInteger: + case TypeArrayPointId: + case TypeArrayPsId: + case TypeArrayPsKey: + case TypeArrayString: + case TypeArrayTime: + case TypeArrayUnitValue: + case TypeUnitValues: default: ok = true @@ -161,7 +170,9 @@ func PrintInt(s int, i interface{}) string { var ret string for range Only.Once { var val int64 - switch reflect.TypeOf(i).String() { + Type := reflect.TypeOf(i).String() + Type = strings.ReplaceAll(Type, "valueTypes.", "") + switch Type { case "int": val = int64(i.(int)) case "int32": @@ -169,15 +180,11 @@ func PrintInt(s int, i interface{}) string { case "int64": val = i.(int64) - case TypeValueTypesInteger: - fallthrough case TypeInteger: val = i.(Integer).Value() - case "valueTypes.Count": - fallthrough case TypeCount: - val = i.(Integer).Value() + val = i.(Count).Value() } if s == 0 { @@ -190,27 +197,25 @@ func PrintInt(s int, i interface{}) string { return ret } -func SizeOfInt(i interface{}) int { +func SizeOfInt(ref interface{}) int { var ret int for range Only.Once { var val int64 - switch reflect.TypeOf(i).String() { + Type := reflect.TypeOf(ref).String() + Type = strings.ReplaceAll(Type, "valueTypes.", "") + switch Type { case "int": - val = int64(i.(int)) + val = int64(ref.(int)) case "int32": - val = int64(i.(int32)) + val = int64(ref.(int32)) case "int64": - val = i.(int64) + val = ref.(int64) - case TypeValueTypesInteger: - fallthrough case TypeInteger: - val = i.(Integer).Value() + val = ref.(Integer).Value() - case TypeValueTypesCount: - fallthrough case TypeCount: - val = i.(Integer).Value() + val = ref.(Count).Value() } switch { case val > 9999: @@ -249,207 +254,14 @@ func SizeOfArrayLength(i interface{}) int { return SizeOfInt(reflect.ValueOf(i).Len()) } -func TypeToString(intSize int, dateFormat string, e interface{}) string { - var ret string - for range Only.Once { - if IsNil(e) { - fmt.Println("NIL") - ret = "NIL" - break - } - - if dateFormat == "" { - dateFormat = DateTimeAltLayout - } - - // fmt.Printf("DEBUG: %s\n", reflect.TypeOf(e).String()) - switch reflect.TypeOf(e).String() { - case "int": - ret = PrintInt(intSize, e.(int)) - case "int32": - ret = PrintInt(intSize, e.(int32)) - case "int64": - ret = PrintInt(intSize, e.(int64)) - case "float32": - // ret = float64(s.(float32)) - v , err := json.Marshal(e) - if err != nil { - break - } - ret = string(v) - case "float64": - // ret = s.(float64) - v , err := json.Marshal(e) - if err != nil { - break - } - ret = string(v) - case "string": - ret = strings.Trim(e.(string), ".") - case "bool": - ret = fmt.Sprintf("%v", e.(bool)) - case "[]string": - // v := strings.Join(s.([]string), ",") - v , err := json.Marshal(e) - if err != nil { - break - } - ret = string(v) - - case TypeValueTypesUnitValue: - fallthrough - case TypeUnitValue: - ret = e.(UnitValue).String() - - case TypeUnitValues: - fallthrough - case TypeArrayUnitValue: - fallthrough - case TypeArrayValueTypesUnitValue: - // ret = s.([]UnitValue) - v , err := json.Marshal(e) - if err != nil { - break - } - ret = string(v) - - case TypeValueTypesFloat: - fallthrough - case TypeFloat: - // ret = s.(Float) - v , err := json.Marshal(e) - if err != nil { - break - } - ret = string(v) - - case TypeArrayValueTypesFloat: - fallthrough - case TypeArrayFloat: - // ret = s.([]Float) - v , err := json.Marshal(e) - if err != nil { - break - } - ret = string(v) - - case TypeValueTypesInteger: - fallthrough - case TypeInteger: - ret = PrintInt(intSize, e.(Integer)) - - case TypeArrayValueTypesInteger: - fallthrough - case TypeArrayInteger: - // ret = s.([]Integer) - v , err := json.Marshal(e) - if err != nil { - break - } - ret = string(v) - - case TypeValueTypesCount: - fallthrough - case TypeCount: - ret = PrintInt(intSize, e.(Count)) - - case TypeArrayValueTypesCount: - fallthrough - case TypeArrayCount: - // ret = s.([]Count) - v , err := json.Marshal(e) - if err != nil { - break - } - ret = string(v) - - case TypeValueTypesBool: - fallthrough - case TypeBool: - ret = e.(Bool).String() - - case TypeArrayValueTypesBool: - fallthrough - case TypeArrayBool: - // ret = s.([]Bool) - v , err := json.Marshal(e) - if err != nil { - break - } - ret = string(v) - - case TypeValueTypesString: - fallthrough - case TypeString: - ret = strings.Trim(e.(String).String(), ".") - - case TypeArrayValueTypesString: - fallthrough - case TypeArrayString: - // ret = s.([]String) - v , err := json.Marshal(e) - if err != nil { - break - } - ret = string(v) - - case TypeValueTypesPsKey: - fallthrough - case TypePsKey: - ret = e.(PsKey).Value() - - case TypeArrayValueTypesPsKey: - fallthrough - case TypeArrayPsKey: - // ret = s.([]PsKey) - v , err := json.Marshal(e) - if err != nil { - break - } - ret = string(v) - - case TypeValueTypesPointId: - fallthrough - case TypePointId: - ret = e.(PointId).String() - - case TypeArrayValueTypesPointId: - fallthrough - case TypeArrayPointId: - // ret = s.([]PointId) - v , err := json.Marshal(e) - if err != nil { - break - } - ret = string(v) - - case TypeValueTypesDateTime: - fallthrough - case TypeDateTime: - ret = e.(DateTime).Format(dateFormat) - - case TypeArrayValueTypesDateTime: - fallthrough - case TypeArrayDateTime: - // ret = s.([]DateTime) - v , err := json.Marshal(e) - if err != nil { - break - } - ret = string(v) - } - } - return ret -} - -func AnyToUnitValue(e interface{}, unit string, Type string, dateFormat string) (UnitValues, bool, bool) { +func AnyToUnitValue(ref interface{}, unit string, typeString string, dateFormat string) (UnitValues, bool, bool) { var uv UnitValues ok := true isNil := false for range Only.Once { - if IsNil(e) { + if IsNil(ref) { // fmt.Println("DEBUG: AnyToUnitValue(): NIL") - uv = append(uv, SetUnitValueString("", unit, Type + "(unknown)")) + uv = append(uv, SetUnitValueString("", unit, typeString + "(unknown)")) isNil = true break } @@ -459,459 +271,407 @@ func AnyToUnitValue(e interface{}, unit string, Type string, dateFormat string) dateFormat = DateTimeAltLayout } - switch reflect.TypeOf(e).String() { + Type := reflect.TypeOf(ref).String() + Type = strings.ReplaceAll(Type, "valueTypes.", "") + switch Type { case "int": - if Type == "" { - Type = "--" + if typeString == "" { + typeString = "--" } - uv = append(uv, SetUnitValueInteger(int64(e.(int)), unit, Type)) + uv = append(uv, SetUnitValueInteger(int64(ref.(int)), unit, typeString)) case "int32": - if Type == "" { - Type = "--" + if typeString == "" { + typeString = "--" } - uv = append(uv, SetUnitValueInteger(int64(e.(int32)), unit, Type)) + uv = append(uv, SetUnitValueInteger(int64(ref.(int32)), unit, typeString)) case "int64": - if Type == "" { - Type = "--" + if typeString == "" { + typeString = "--" } - uv = append(uv, SetUnitValueInteger(e.(int64), unit, Type)) + uv = append(uv, SetUnitValueInteger(ref.(int64), unit, typeString)) case "float32": - if Type == "" { - Type = "--" + if typeString == "" { + typeString = "--" } - uv = append(uv, SetUnitValueFloat(float64(e.(float32)), unit, Type)) + uv = append(uv, SetUnitValueFloat(float64(ref.(float32)), unit, typeString)) case "float64": - if Type == "" { - Type = "--" + if typeString == "" { + typeString = "--" } - uv = append(uv, SetUnitValueFloat(e.(float64), unit, Type)) + uv = append(uv, SetUnitValueFloat(ref.(float64), unit, typeString)) case "string": - if Type == "" { - Type = "--" + if typeString == "" { + typeString = "--" } - uv = append(uv, SetUnitValueString(e.(string), unit, Type)) + uv = append(uv, SetUnitValueString(ref.(string), unit, typeString)) case "[]string": // v := strings.Join(e.([]string), ",") - if Type == "" { - Type = "--" + if typeString == "" { + typeString = "--" } - j, err := json.Marshal(e.([]string)) + j, err := json.Marshal(ref.([]string)) if err != nil { - j = []byte(fmt.Sprintf("%v", e.([]string))) + j = []byte(fmt.Sprintf("%v", ref.([]string))) } - uv = append(uv, SetUnitValueString(string(j), unit, Type)) + uv = append(uv, SetUnitValueString(string(j), unit, typeString)) case "bool": - if Type == "" { - Type = "--" + if typeString == "" { + typeString = "--" } - uv = append(uv, SetUnitValueBool(e.(bool))) + uv = append(uv, SetUnitValueBool(ref.(bool))) - case TypeValueTypesUnitValue: - fallthrough case TypeUnitValue: - if Type == "" { - Type = "--" + if typeString == "" { + typeString = "--" } - uv = append(uv, e.(UnitValue)) + uv = append(uv, ref.(UnitValue)) // uv = uv.UnitValueFix() - case TypeUnitValues: fallthrough - case TypeArrayValueTypesUnitValue: - fallthrough case TypeArrayUnitValue: - for _, val := range e.([]UnitValue) { + for _, val := range ref.([]UnitValue) { uv = append(uv, val) } - case TypeValueTypesFloat: - fallthrough case TypeFloat: - if Type == "" { - Type = TypeFloat + if typeString == "" { + typeString = TypeFloat } - v := e.(Float) - uv = append(uv, SetUnitValueFloat(v.Value(), unit, Type)) - - case TypeArrayValueTypesFloat: - fallthrough + v := ref.(Float) + uv = append(uv, SetUnitValueFloat(v.Value(), unit, typeString)) case TypeArrayFloat: - if Type == "" { - Type = TypeFloat + if typeString == "" { + typeString = TypeFloat } - v := e.([]Float) + v := ref.([]Float) for _, val := range v { - uv = append(uv, SetUnitValueFloat(val.Value(), unit, Type)) + uv = append(uv, SetUnitValueFloat(val.Value(), unit, typeString)) } - case TypeValueTypesInteger: - fallthrough case TypeInteger: - if Type == "" { - Type = TypeInteger + if typeString == "" { + typeString = TypeInteger } - v := e.(Integer).Value() - uv = append(uv, SetUnitValueInteger(v, unit, Type)) - - case TypeArrayValueTypesInteger: - fallthrough + v := ref.(Integer) + uv = append(uv, SetUnitValueInteger(v.Value(), unit, typeString)) case TypeArrayInteger: - if Type == "" { - Type = TypeInteger + if typeString == "" { + typeString = TypeInteger } - v := e.([]Integer) + v := ref.([]Integer) for _, val := range v { - uv = append(uv, SetUnitValueInteger(val.Value(), unit, Type)) + uv = append(uv, SetUnitValueInteger(val.Value(), unit, typeString)) } // HERE IS THE PROBLEM - need to return SOMETHING, even if it's null! - case TypeValueTypesCount: - fallthrough case TypeCount: - if Type == "" { - Type = TypeCount + if typeString == "" { + typeString = TypeCount } - v := e.(Count).Value() - uv = append(uv, SetUnitValueInteger(v, unit, Type)) - - case TypeArrayValueTypesCount: - fallthrough + v := ref.(Count) + uv = append(uv, SetUnitValueInteger(v.Value(), unit, typeString)) case TypeArrayCount: - if Type == "" { - Type = TypeCount + if typeString == "" { + typeString = TypeCount } - v := e.([]Count) + v := ref.([]Count) for _, val := range v { - uv = append(uv, SetUnitValueInteger(val.Value(), unit, Type)) + uv = append(uv, SetUnitValueInteger(val.Value(), unit, typeString)) } - case TypeValueTypesBool: - fallthrough case TypeBool: - if Type == "" { - Type = TypeBool + if typeString == "" { + typeString = TypeBool } - v := e.(Bool) + v := ref.(Bool) uv = append(uv, SetUnitValueBool(v.Value())) - - case TypeArrayValueTypesBool: - fallthrough case TypeArrayBool: - if Type == "" { - Type = TypeBool + if typeString == "" { + typeString = TypeBool } - v := e.([]Bool) + v := ref.([]Bool) for _, val := range v { - // uv = append(uv, SetUnitValueString(val.String(), unit, Type)) uv = append(uv, SetUnitValueBool(val.Value())) } - case TypeValueTypesString: - fallthrough case TypeString: - if Type == "" { - Type = TypeString + if typeString == "" { + typeString = TypeString } - v := e.(String).String() - uv = append(uv, SetUnitValueString(v, unit, Type)) - - case TypeArrayValueTypesString: - fallthrough + v := ref.(String) + uv = append(uv, SetUnitValueString(v.String(), unit, typeString)) case TypeArrayString: - if Type == "" { - Type = TypeString + if typeString == "" { + typeString = TypeString } - v := e.([]String) + v := ref.([]String) for _, val := range v { - uv = append(uv, SetUnitValueString(val.Value(), unit, Type)) + uv = append(uv, SetUnitValueString(val.Value(), unit, typeString)) + } + + case TypePsId: + if typeString == "" { + typeString = TypePsId + } + v := ref.(PsId) + uv = append(uv, SetUnitValueString(v.String(), unit, typeString)) + + case TypeArrayPsId: + if typeString == "" { + typeString = TypePsId + } + v := ref.([]PsId) + for _, val := range v { + uv = append(uv, SetUnitValueString(val.String(), unit, typeString)) } - case TypeValueTypesPsKey: - fallthrough case TypePsKey: - if Type == "" { - Type = TypePsKey + if typeString == "" { + typeString = TypePsKey } - v := e.(PsKey).Value() - uv = append(uv, SetUnitValueString(v, unit, Type)) + v := ref.(PsKey) + uv = append(uv, SetUnitValueString(v.Value(), unit, typeString)) - case TypeArrayValueTypesPsKey: - fallthrough case TypeArrayPsKey: - if Type == "" { - Type = TypePsKey + if typeString == "" { + typeString = TypePsKey } - v := e.([]PsKey) + v := ref.([]PsKey) for _, val := range v { - uv = append(uv, SetUnitValueString(val.Value(), unit, Type)) + uv = append(uv, SetUnitValueString(val.Value(), unit, typeString)) } - case TypeValueTypesPointId: - fallthrough case TypePointId: - if Type == "" { - Type = TypePointId + if typeString == "" { + typeString = TypePointId } - v := e.(PointId).String() - uv = append(uv, SetUnitValueString(v, unit, Type)) - - case TypeArrayValueTypesPointId: - fallthrough + v := ref.(PointId) + uv = append(uv, SetUnitValueString(v.String(), unit, typeString)) case TypeArrayPointId: - if Type == "" { - Type = TypePointId + if typeString == "" { + typeString = TypePointId } - v := e.([]PointId) + v := ref.([]PointId) for _, val := range v { - uv = append(uv, SetUnitValueString(val.String(), unit, Type)) + uv = append(uv, SetUnitValueString(val.String(), unit, typeString)) } - case TypeValueTypesDateTime: - fallthrough case TypeDateTime: - if Type == "" { - Type = TypeDateTime + if typeString == "" { + typeString = TypeDateTime } - v := e.(DateTime).Format(dateFormat) - uv = append(uv, SetUnitValueString(v, unit, Type)) - - case TypeArrayValueTypesDateTime: - fallthrough + v := ref.(DateTime) + uv = append(uv, SetUnitValueString(v.Format(dateFormat), unit, typeString)) case TypeArrayDateTime: - if Type == "" { - Type = TypeDateTime + if typeString == "" { + typeString = TypeDateTime } - v := e.([]DateTime) + v := ref.([]DateTime) for _, val := range v { - uv = append(uv, SetUnitValueString(val.Format(dateFormat), unit, Type)) + uv = append(uv, SetUnitValueString(val.Format(dateFormat), unit, typeString)) } - case TypeValueTypesTime: - fallthrough case TypeTime: - if Type == "" { - Type = TypeTime + if typeString == "" { + typeString = TypeTime } - v := e.(Time).Format(TimeLayout) - uv = append(uv, SetUnitValueString(v, unit, Type)) - - case TypeArrayValueTypesTime: - fallthrough + v := ref.(Time) + uv = append(uv, SetUnitValueString(v.Format(TimeLayout), unit, typeString)) case TypeArrayTime: - if Type == "" { - Type = TypeTime + if typeString == "" { + typeString = TypeTime } - v := e.([]Time) + v := ref.([]Time) for _, val := range v { - uv = append(uv, SetUnitValueString(val.Format(TimeLayout), unit, Type)) + uv = append(uv, SetUnitValueString(val.Format(TimeLayout), unit, typeString)) } default: - uv = append(uv, SetUnitValueString("", unit, Type + "(unknown)")) + uv = append(uv, SetUnitValueString("", unit, typeString+ "(unknown)")) ok = false } } return uv, isNil, ok } -func AnyToValueString(e interface{}, intSize int, dateFormat string) string { +func AnyToValueString(ref interface{}, intSize int, dateFormat string) string { var ret string for range Only.Once { - if IsNil(e) { + if IsNil(ref) { break } - if dateFormat == "" { - dateFormat = DateTimeAltLayout - } - // fmt.Printf("DEBUG TYPE: %s\n", reflect.TypeOf(e).String()) - switch reflect.TypeOf(e).String() { + Type := reflect.TypeOf(ref).String() + Type = strings.ReplaceAll(Type, "valueTypes.", "") + switch Type { case "bool": - ret = fmt.Sprintf("%v", e.(bool)) + ret = fmt.Sprintf("%v", ref.(bool)) case "int": - ret = PrintInt(intSize, e.(int)) + ret = PrintInt(intSize, ref.(int)) case "int32": - ret = PrintInt(intSize, e.(int32)) + ret = PrintInt(intSize, ref.(int32)) case "int64": - ret = PrintInt(intSize, e.(int64)) + ret = PrintInt(intSize, ref.(int64)) case "float32": // ret = float64(s.(float32)) - v , err := json.Marshal(e) + v , err := json.Marshal(ref) if err != nil { break } ret = string(v) case "float64": // ret = s.(float64) - v , err := json.Marshal(e) + v , err := json.Marshal(ref) if err != nil { break } ret = string(v) case "string": - ret = e.(string) - // ret = strings.Trim(e.(string), ".") + ret = ref.(string) + // ret = strings.Trim(ref.(string), ".") case "[]string": // v := strings.Join(s.([]string), ",") - v , err := json.Marshal(e) + v , err := json.Marshal(ref) if err != nil { break } ret = string(v) - case TypeValueTypesUnitValue: - fallthrough case TypeUnitValue: - ret = e.(UnitValue).String() - + ret = ref.(UnitValue).String() case TypeUnitValues: fallthrough case TypeArrayUnitValue: - fallthrough - case TypeArrayValueTypesUnitValue: // ret = s.([]UnitValue) - v , err := json.Marshal(e) + v , err := json.Marshal(ref) if err != nil { break } ret = string(v) - case TypeValueTypesFloat: - fallthrough case TypeFloat: - ret = e.(Float).String() - - case TypeArrayValueTypesFloat: - fallthrough + ret = ref.(Float).String() + // v , err := json.Marshal(ref) + // if err != nil { + // break + // } + // ret = string(v) case TypeArrayFloat: // ret = s.([]Float) - v , err := json.Marshal(e) + v , err := json.Marshal(ref) if err != nil { break } ret = string(v) - case TypeValueTypesInteger: - fallthrough case TypeInteger: - ret = PrintInt(intSize, e.(Integer)) - - case TypeArrayValueTypesInteger: - fallthrough + ret = PrintInt(intSize, ref.(Integer)) case TypeArrayInteger: // ret = s.([]Integer) - v , err := json.Marshal(e) + v , err := json.Marshal(ref) if err != nil { break } ret = string(v) - case TypeValueTypesCount: - fallthrough case TypeCount: - ret = PrintInt(intSize, e.(Count)) - - case TypeArrayValueTypesCount: - fallthrough + ret = PrintInt(intSize, ref.(Count)) case TypeArrayCount: // ret = s.([]Count) - v , err := json.Marshal(e) + v , err := json.Marshal(ref) if err != nil { break } ret = string(v) - case TypeValueTypesBool: - fallthrough case TypeBool: - ret = e.(Bool).String() - - case TypeArrayValueTypesBool: - fallthrough + ret = ref.(Bool).String() case TypeArrayBool: // ret = s.([]Bool) - v , err := json.Marshal(e) + v , err := json.Marshal(ref) if err != nil { break } ret = string(v) - case TypeValueTypesString: - fallthrough case TypeString: - ret = e.(String).String() - - case TypeArrayValueTypesString: - fallthrough + ret = ref.(String).String() + // ret = strings.Trim(ref.(String).String(), ".") case TypeArrayString: // ret = s.([]String) - v , err := json.Marshal(e) + v , err := json.Marshal(ref) if err != nil { break } ret = string(v) - case TypeValueTypesPsKey: - fallthrough case TypePsKey: - ret = e.(PsKey).Value() - - case TypeArrayValueTypesPsKey: - fallthrough + ret = ref.(PsKey).String() case TypeArrayPsKey: // ret = s.([]PsKey) - v , err := json.Marshal(e) + v , err := json.Marshal(ref) if err != nil { break } ret = string(v) - case TypeValueTypesPointId: - fallthrough - case TypePointId: - ret = e.(PointId).String() + case TypePsId: + ret = ref.(PsId).String() + case TypeArrayPsId: + // ret = s.([]PsId) + v , err := json.Marshal(ref) + if err != nil { + break + } + ret = string(v) - case TypeArrayValueTypesPointId: - fallthrough + case TypePointId: + ret = ref.(PointId).String() case TypeArrayPointId: // ret = s.([]PointId) - v , err := json.Marshal(e) + v , err := json.Marshal(ref) if err != nil { break } ret = string(v) - case TypeValueTypesDateTime: - fallthrough case TypeDateTime: - v := e.(DateTime) + if dateFormat == "" { + dateFormat = DateTimeAltLayout + } + v := ref.(DateTime) if v.IsZero() { ret = "" break } ret = v.Format(dateFormat) - - case TypeArrayValueTypesDateTime: - fallthrough case TypeArrayDateTime: // ret = s.([]DateTime) - v , err := json.Marshal(e) + v , err := json.Marshal(ref) if err != nil { break } ret = string(v) - case TypeValueTypesTime: - fallthrough case TypeTime: - v := e.(Time) + if dateFormat == "" { + dateFormat = TimeLayoutSecond + } + v := ref.(Time) if v.IsZero() { ret = "" break } ret = v.Format(dateFormat) + case TypeArrayTime: + // ret = s.([]Time) + v , err := json.Marshal(ref) + if err != nil { + break + } + ret = string(v) default: } diff --git a/iSolarCloud/api/valueTypes/uv.go b/iSolarCloud/api/valueTypes/uv.go index d4410d802..b3a6eddd7 100644 --- a/iSolarCloud/api/valueTypes/uv.go +++ b/iSolarCloud/api/valueTypes/uv.go @@ -2,6 +2,7 @@ package valueTypes import ( "encoding/json" + "fmt" "github.com/MickMake/GoUnify/Only" "sort" "strconv" @@ -33,6 +34,8 @@ func (t *UnitValue) UnitValueFix() UnitValue { } switch t.UnitValue { + case "g": + fallthrough case "Wp": fallthrough case "Wh": @@ -53,6 +56,67 @@ func (t *UnitValue) UnitValueFix() UnitValue { return *t } +func UnitValueType(unit string) string { + var ret string + switch unit { + case "Wh": + fallthrough + case "kWh": + fallthrough + case "MWh": + ret = "Energy" + + case "kWp": + fallthrough + case "W": + fallthrough + case "kW": + fallthrough + case "MW": + ret = "Power" + + case "AUD": + ret = "Currency" + + case "g": + fallthrough + case "kg": + ret = "Weight" + + case "mV": + fallthrough + case "V": + ret = "Voltage" + + case "mA": + fallthrough + case "A": + ret = "Current" + + case "Hz": + ret = "Frequency" + + case "kvar": + ret = "Reactive Power" + + case "Ω": + fallthrough + case "kΩ": + ret = "Resistance" + + case "%": + ret = "Percent" + + case "F": + fallthrough + case "C": + fallthrough + case "℃": + ret = "Temperature" + } + return ret +} + // UnmarshalJSON - Convert JSON to value func (t *UnitValue) UnmarshalJSON(data []byte) error { for range Only.Once { @@ -157,6 +221,8 @@ func (t UnitValue) MarshalJSON() ([]byte, error) { } } + data = []byte(fmt.Sprintf(`{"unit":"%s","value":"--"}`, t.UnitValue)) + t.Valid = true } @@ -402,6 +468,7 @@ func (t *UnitValue) SetBoolString(value string) UnitValue { func (t *UnitValue) SetUnit(unit string) UnitValue { for range Only.Once { t.UnitValue = unit + t.TypeValue = UnitValueType(unit) } return *t diff --git a/iSolarCloud/api/web.go b/iSolarCloud/api/web.go index 3389c1b5c..007f7739e 100644 --- a/iSolarCloud/api/web.go +++ b/iSolarCloud/api/web.go @@ -75,6 +75,11 @@ func (w *Web) Get(endpoint EndPoint) EndPoint { break } endpoint = endpoint.SetResponse(w.Body) + if endpoint.GetError() != nil { + w.Error = endpoint.GetError() + break + } + w.Error = endpoint.IsResponseValid() if w.Error != nil { _ = w.WebCacheRemove(endpoint) diff --git a/iSolarCloud/data.go b/iSolarCloud/data.go index 1e3ff23ad..914fc9406 100644 --- a/iSolarCloud/data.go +++ b/iSolarCloud/data.go @@ -17,9 +17,12 @@ import ( "strings" ) + // ****************************************************** // -func (sg *SunGrow) GetEndpoints(endpoints []string, psIds []valueTypes.Integer, date valueTypes.DateTime, reportType string, faultTypeCode string) error { +// func (sg *SunGrow) GetEndpoints(endpoints []string, psIds []string, date string, reportType string, faultTypeCode string) error { + +func (sg *SunGrow) GetEndpoints(endpoints []string, args ...string) error { for range Only.Once { var data SunGrowData data.New(sg) @@ -37,24 +40,22 @@ func (sg *SunGrow) GetEndpoints(endpoints []string, psIds []valueTypes.Integer, endpoints = data.GetAllEndPoints() } - if len(psIds) == 0 { - psIds, sg.Error = sg.GetPsIds() + var request SunGrowDataRequest + request = request.Set(args...) + + for _, endpoint := range endpoints { + ep := sg.GetEndpoint(endpoint) + sg.Error = ep.GetError() if sg.Error != nil { break } - } - if date.IsZero() { - date = valueTypes.NewDateTime(valueTypes.Now) - } + rargs := ep.GetRequestArgNames() + // fmt.Printf("args:%s\n", rargs) - for _, endpoint := range endpoints { - args := sg.RequestArgs(endpoint) - fmt.Printf("args:%s\n", args) - if len(args) == 0 { - // We don't have any request args. - req := SunGrowDataRequest {} - response := data.GetByApi(endpoint, req) + if _, ok := rargs[NamePsId]; !ok { + // We don't have any request PsId args. + response := data.GetByApi(ep, request) if response.Error != nil { sg.Error = response.Error break @@ -63,62 +64,29 @@ func (sg *SunGrow) GetEndpoints(endpoints []string, psIds []valueTypes.Integer, sg.Error = data.Error break } + response.Table.SetFilePrefix(request.GetFilename(endpoint)) sg.Error = response.Table.Output() if sg.Error != nil { break } - - continue } - if _, ok := args["PsId"]; !ok { - // If we don't need a PsId - req := SunGrowDataRequest { - Date: date, - ReportType: reportType, - FaultTypeCode: faultTypeCode, - } - response := data.GetByApi(endpoint, req) - if response.Error != nil { - sg.Error = response.Error - break - } - if data.Error != nil { - sg.Error = data.Error - break - } - sg.Error = response.Table.Output() - if sg.Error != nil { - break - } - - continue - } - - if _, ok := args["PsId"]; ok { + // This method merges all ps_ids + if _, ok := rargs[NamePsId]; ok { var finalData api.DataMap - finalFilename := endpoint + "_" + var finalRaw []byte - for _, psId := range psIds { - finalFilename += psId.String() + "-" + var pids valueTypes.PsIds + pids, sg.Error = sg.GetPsIds() + if sg.Error != nil { + break + } + request.SetPsIds(pids.Strings()) - req := SunGrowDataRequest { - PsId: psId, - Date: date, - ReportType: reportType, - FaultTypeCode: faultTypeCode, - } + for _, psId := range pids { + request.SetPsId(psId.String()) - // if data.HasArgs(endpoint) { - // } - // _, ok := data.FuncExists(endpoint) - // if ok { - // response = data.GetByFunc(endpoint, req) - // } else { - // data.Error = nil - // response = data.GetByApi(endpoint, req) - // } - response := data.GetByApi(endpoint, req) + response := data.GetByApi(ep, request) if response.Error != nil { sg.Error = response.Error break @@ -129,14 +97,21 @@ func (sg *SunGrow) GetEndpoints(endpoints []string, psIds []valueTypes.Integer, } finalData.AppendMap(response.Data) + finalRaw = append(finalRaw, response.Table.GetRawBytes()...) } + if sg.Error != nil { + fmt.Printf("Error: %s\n", sg.Error) + break + } + + request.SetPsId(strings.Join(request.aPsId.Strings(), "_")) // Hackety hack. finalTable := finalData.CreateTable() // response.Table.SetTitle(response.Title) - finalFilename = strings.TrimSuffix(finalFilename, "-") - finalTable.SetFilePrefix(finalFilename) + finalTable.SetFilePrefix(request.GetFilename(endpoint)) finalTable.SetGraphFilter("") finalTable.SetSaveFile(sg.SaveAsFile) + finalTable.SetRaw(finalRaw) finalTable.OutputType = sg.OutputType sg.Error = finalTable.Output() @@ -144,6 +119,7 @@ func (sg *SunGrow) GetEndpoints(endpoints []string, psIds []valueTypes.Integer, break } } + } } @@ -151,13 +127,6 @@ func (sg *SunGrow) GetEndpoints(endpoints []string, psIds []valueTypes.Integer, } -type SunGrowData struct { - EndPoint string - EndPoints EndPoints - SunGrow *SunGrow - Error error -} - type EndPoints map[string]EndPoint type EndPoint struct { Func SunGrowDataFunction @@ -165,12 +134,363 @@ type EndPoint struct { } type SunGrowDataFunction func(request SunGrowDataRequest) SunGrowDataResponse + +// SunGrowDataRequest - Collection of all possible request args. type SunGrowDataRequest struct { - PsId valueTypes.Integer `json:"ps_id,omitempty"` - ReportType string `json:"report_type,omitempty"` - Date valueTypes.DateTime `json:"date,omitempty"` - FaultTypeCode string `json:"fault_type_code,omitempty"` + PsId *valueTypes.PsId `json:"ps_id,omitempty"` + ReportType *string `json:"report_type,omitempty"` + DateId *valueTypes.DateTime `json:"date_id,omitempty"` + DateType *string `json:"date_type,omitempty"` + FaultTypeCode *string `json:"fault_type_code,omitempty"` + Size *valueTypes.Integer `json:"page_size,omitempty"` + CurPage *valueTypes.Integer `json:"cur_page,omitempty"` + DeviceType *valueTypes.String `json:"device_type,omitempty"` + ReportId *valueTypes.String `json:"report_id,omitempty"` + CodeType *valueTypes.String `json:"code_type,omitempty"` + OrgIds *valueTypes.String `json:"orgIds,omitempty"` + PsIdList *valueTypes.String `json:"ps_id_list,omitempty"` + + aPsId valueTypes.PsIds } + +const ( + NamePsId = "PsId" + NameReportType = "ReportType" + NameDateId = "DateId" + NameDateType = "DateType" + NameFaultTypeCode = "FaultTypeCode" + NameSize = "Size" + NameCurPage = "CurPage" + NameDeviceType = "DeviceType" + NameReportId = "ReportId" + NameCodeType = "CodeType" + NameOrgIds = "OrgIds" + NamePsIdList = "PsIdList" +) + +// MarshalJSON - Convert value to JSON +func (sgd SunGrowDataRequest) MarshalJSON() ([]byte, error) { + var data []byte + var err error + + for range Only.Once { + var dt *string + if sgd.DateId != nil { + dt = &sgd.DateId.DateType + } + + type Parse SunGrowDataRequest + // Store result from string + data, err = json.Marshal(Parse { + PsId: sgd.PsId, + ReportType: sgd.ReportType, + DateId: sgd.DateId, + DateType: dt, + FaultTypeCode: sgd.FaultTypeCode, + Size: sgd.Size, + CurPage: sgd.CurPage, + DeviceType: sgd.DeviceType, + ReportId: sgd.ReportId, + CodeType: sgd.CodeType, + OrgIds: sgd.OrgIds, + PsIdList: sgd.PsIdList, + }) + if err == nil { + break + } + } + + return data, err +} + +func (sgd *SunGrowDataRequest) Set(args ...string) SunGrowDataRequest { + var request SunGrowDataRequest + for range Only.Once { + for _, arg := range args { + a := strings.Split(arg, ":") + if len(a) == 0 { + continue + } + + if len(a) == 1 { + a = append(a, "") + } + + switch a[0] { + case NamePsId: + request.aPsId = valueTypes.SetPsIdStrings(strings.Split(a[1], ",")) + + case NameReportType: + request.ReportType = &a[1] + + case NameDateId: + val := valueTypes.SetDateTimeString(a[1]) + request.DateId = &val + + case NameFaultTypeCode: + request.FaultTypeCode = &a[1] + + case NameSize: + val := valueTypes.SetIntegerString(a[1]) + request.Size = &val + + case NameCurPage: + val := valueTypes.SetIntegerString(a[1]) + request.CurPage = &val + + case NameDeviceType: + val := valueTypes.SetStringValue(a[1]) + request.DeviceType = &val + + case NameReportId: + val := valueTypes.SetStringValue(a[1]) + request.ReportId = &val + + case NameCodeType: + val := valueTypes.SetStringValue(a[1]) + request.CodeType = &val + + case NameOrgIds: + val := valueTypes.SetStringValue(a[1]) + request.OrgIds = &val + + case NamePsIdList: + val := valueTypes.SetStringValue(a[1]) + request.PsIdList = &val + } + } + } + return request +} + +func (sgd *SunGrowDataRequest) Validate(endpoint api.EndPoint) bool { + ok := true + for range Only.Once { + args := endpoint.GetRequestArgNames() + for key, value := range args { + if value != "true" { + continue + } + switch key { + case NamePsId: + // if sgd.PsId == nil { + // fmt.Printf("%s is required\n", key) + // ok = false + // } + + case NameReportType: + if sgd.ReportType == nil { + fmt.Printf("%s is required\n", key) + ok = false + } + + case NameDateId: + if sgd.DateId == nil { + fmt.Printf("%s is required\n", key) + ok = false + } + + case NameFaultTypeCode: + if sgd.FaultTypeCode == nil { + fmt.Printf("%s is required\n", key) + ok = false + } + + case NameSize: + if sgd.Size == nil { + fmt.Printf("%s is required\n", key) + ok = false + } + + case NameCurPage: + if sgd.CurPage == nil { + fmt.Printf("%s is required\n", key) + ok = false + } + + case NameDeviceType: + if sgd.DeviceType == nil { + fmt.Printf("%s is required\n", key) + ok = false + } + + case NameReportId: + if sgd.ReportId == nil { + fmt.Printf("%s is required\n", key) + ok = false + } + + case NameCodeType: + if sgd.CodeType == nil { + fmt.Printf("%s is required\n", key) + ok = false + } + + case NameOrgIds: + if sgd.OrgIds == nil { + fmt.Printf("%s is required\n", key) + ok = false + } + + case NamePsIdList: + if sgd.PsIdList == nil { + fmt.Printf("%s is required\n", key) + ok = false + } + } + } + } + return ok +} + +// func (sgd *SunGrowDataRequest) Create(endpoint api.EndPoint) SunGrowDataRequest { +// var request SunGrowDataRequest +// for range Only.Once { +// args := endpoint.GetRequestArgNames() +// for key, value := range args { +// if value != "true" { +// continue +// } +// switch key { +// case NamePsId: +// request.PsId = sgd.PsId +// +// case NameReportType: +// request.ReportType = sgd.ReportType +// if *request.ReportType == "" { +// *request.ReportType = "1" +// } +// +// case NameDateId: +// request.DateId = sgd.DateId +// if request.DateId.IsZero() { +// did := valueTypes.SetDateTimeString(time.Now().Format(valueTypes.DateTimeLayoutDay)) +// request.DateId = &did +// } +// +// case NameFaultTypeCode: +// request.FaultTypeCode = sgd.FaultTypeCode +// +// case NameSize: +// request.Size = sgd.Size +// if request.Size.Value() == 0 { +// request.Size.SetValue(100) +// } +// +// case NameCurPage: +// request.CurPage = sgd.CurPage +// if request.CurPage.Value() == 0 { +// request.CurPage.SetValue(1) +// } +// +// case NameDeviceType: +// request.DeviceType = sgd.DeviceType +// // if request.DeviceType.String() == "" { +// // request.DeviceType.SetValue("14") // @TODO - Need to lookup the first device_type. +// // } +// +// case NameReportId: +// request.ReportId = sgd.ReportId +// // if request.ReportId.String() == "" { +// // request.ReportId.SetValue("8042") // @TODO - Need to lookup the first device_type. +// // } +// +// case NameCodeType: +// request.CodeType = sgd.CodeType +// } +// } +// } +// return request +// } + +func (sgd *SunGrowDataRequest) Help(endpoint api.EndPoint) { + for range Only.Once { + args := endpoint.GetRequestArgNames() + for key, value := range args { + if key == NamePsId { + continue + } + + if key == NameDateType { + continue + } + + if value != "true" { + fmt.Printf("optional - %s:value\n", key) + continue + } + + fmt.Printf("required - %s:value\n", key) + } + } +} + +func (sgd *SunGrowDataRequest) GetFilename(prefix string) string { + var ret string + for range Only.Once { + var aret []string + + aret = append(aret, prefix) + if sgd.PsId != nil { + if sgd.PsId.String() != "" { + aret = append(aret, sgd.PsId.String()) + } + } + + if sgd.DateId != nil { + if sgd.DateId.Original() != "" { + aret = append(aret, sgd.DateId.Original()) + } + } + + if sgd.ReportType != nil { + if *sgd.ReportType != "" { + aret = append(aret, *sgd.ReportType) + } + } + + if sgd.FaultTypeCode != nil { + if *sgd.FaultTypeCode != "" { + aret = append(aret, *sgd.FaultTypeCode) + } + } + + ret = strings.Join(aret, "-") + } + return ret +} + +func (sgd *SunGrowDataRequest) SetDate(date string) { + did := valueTypes.SetDateTimeString(date) + sgd.DateId = &did + if sgd.DateId.IsZero() { + did = valueTypes.NewDateTime(valueTypes.Now) + sgd.DateId = &did + } +} + +func (sgd *SunGrowDataRequest) SetFaultTypeCode(ftc string) { + sgd.FaultTypeCode = &ftc +} + +func (sgd *SunGrowDataRequest) SetReportType(rt string) { + sgd.ReportType = &rt +} + +func (sgd *SunGrowDataRequest) SetPsIds(psIds []string) { + sgd.aPsId = valueTypes.SetPsIdStrings(psIds) +} + +func (sgd *SunGrowDataRequest) GetPsIds() valueTypes.PsIds { + return sgd.aPsId +} + +func (sgd *SunGrowDataRequest) SetPsId(psId string) { + pid := valueTypes.SetPsIdString(psId) + sgd.PsId = &pid +} + + type SunGrowDataResponse struct { Data api.DataMap Table output.Table @@ -180,6 +500,13 @@ type SunGrowDataResponse struct { } +type SunGrowData struct { + // EndPoint string + EndPoints EndPoints + SunGrow *SunGrow + Error error +} + func (sgd *SunGrowData) New(ref *SunGrow) { for range Only.Once { sgd.SunGrow = ref @@ -266,35 +593,97 @@ func (sgd *SunGrowData) GetByFunc(endpoint string, request SunGrowDataRequest) S return response } -func (sgd *SunGrowData) GetByApi(endpoint string, request SunGrowDataRequest) SunGrowDataResponse { +func (sgd *SunGrowData) GetByEndPointName(endpoint string, request SunGrowDataRequest) SunGrowDataResponse { var response SunGrowDataResponse response.Table = output.NewTable() for range Only.Once { - req, err := json.Marshal(request) - if err != nil { - fmt.Printf("GetByApi - ERR: %s\n", err) + ep := sgd.SunGrow.GetEndpoint(endpoint) + sgd.SunGrow.Error = ep.GetError() + if sgd.SunGrow.Error != nil { + break } + response = sgd.GetByApi(ep, request) + } + return response +} - data := sgd.SunGrow.GetByJson(endpoint, string(req)) - if data.IsError() { - sgd.Error = data.GetError() +func (sgd *SunGrowData) GetByApi(endpoint api.EndPoint, request SunGrowDataRequest) SunGrowDataResponse { + var response SunGrowDataResponse + response.Table = output.NewTable() + for range Only.Once { + + if !request.Validate(endpoint) { + request.Help(endpoint) break } - fn := "" - if request.PsId.String() != "" { - fn += "-" + request.PsId.String() + var req []byte + req, sgd.Error = json.Marshal(request) + if sgd.Error != nil { + fmt.Printf("GetByApi - ERR: %s\n", sgd.Error) + break } - if !request.Date.IsZero() { - fn += "-" + request.Date.Original() + fmt.Printf("%s\n", req) + + // newRequest := request.Create(endpoint) + + if string(req) != "" { + endpoint = endpoint.SetRequestByJson(output.Json(req)) + sgd.Error = endpoint.GetError() + if sgd.Error != nil { + fmt.Println(endpoint.Help()) + break + } } - response.Filename = data.SetFilenamePrefix(fn) + fmt.Printf("%s\n", endpoint.GetRequestJson()) + + endpoint = endpoint.Call() + sgd.Error = endpoint.GetError() + if sgd.Error != nil { + if strings.Contains(sgd.Error.Error(), "er_token_login_invalid") { + sgd.SunGrow.Logout() + break + } + fmt.Println(endpoint.Help()) + break + } + + // switch { + // case sgd.SunGrow.OutputType.IsNone(): + // + // case sgd.SunGrow.OutputType.IsRaw(): + // if sgd.SunGrow.SaveAsFile { + // sgd.SunGrow.Error = ep.WriteDataFile() + // break + // } + // fmt.Println(ep.GetJsonData(true)) + // + // case sgd.SunGrow.OutputType.IsJson(): + // if sgd.SunGrow.SaveAsFile { + // sgd.SunGrow.Error = ep.WriteDataFile() + // break + // } + // fmt.Println(ep.GetJsonData(false)) + // + // default: + // } + + // var fn []string + // if request.PsId.String() != "" { + // fn = append(fn, request.PsId.String()) + // } + // if !request.DateId.IsZero() { + // fn = append(fn, request.DateId.Original()) + // } + response.Filename = request.GetFilename("") + response.Filename = endpoint.SetFilenamePrefix(response.Filename) + // response.Filename = request.CreateFilename(ep) if response.Title == "" { response.Title = fmt.Sprintf("Data Request %s", endpoint) } - response.Data = data.GetEndPointData() - response.Table = data.GetEndPointDataTable() + response.Data = endpoint.GetEndPointData() + response.Table = endpoint.GetEndPointDataTable() // response.Table.SetTitle(response.Title) response.Table.SetFilePrefix(response.Filename) response.Table.SetGraphFilter("") @@ -410,7 +799,7 @@ func (sgd *SunGrowData) findCodeValueList(request SunGrowDataRequest) SunGrowDat ep := sgd.SunGrow.GetByStruct( "AppService.findCodeValueList", // findCodeValueList.RequestData{ PsId: request.PsId }, - findCodeValueList.RequestData{ CodeType: "1" }, + findCodeValueList.RequestData{ CodeType: *request.CodeType }, api.DefaultTimeout, ) diff --git a/iSolarCloud/highlevel.go b/iSolarCloud/highlevel.go index 1775ed145..d9f0f44b1 100644 --- a/iSolarCloud/highlevel.go +++ b/iSolarCloud/highlevel.go @@ -40,7 +40,7 @@ func (sg *SunGrow) GetPointNamesFromTemplate(template string) api.TemplatePoints ep := sg.GetByStruct( "WebAppService.queryUserCurveTemplateData", - queryUserCurveTemplateData.RequestData{TemplateID: template}, + queryUserCurveTemplateData.RequestData{TemplateId: template}, time.Hour, ) if sg.Error != nil { @@ -55,7 +55,7 @@ func (sg *SunGrow) GetPointNamesFromTemplate(template string) api.TemplatePoints } ret = append(ret, api.TemplatePoint { PsKey: dn, - PointId: pr.PointID, + PointId: pr.PointId, Name: pr.PointName, Unit: pr.Unit, }) @@ -77,7 +77,7 @@ func (sg *SunGrow) GetTemplateData(template string, date string, filter string) } when := valueTypes.NewDateTime(date) - var psIds []valueTypes.Integer + var psIds []valueTypes.PsId psIds, sg.Error = sg.StringToPids() if sg.Error != nil { break @@ -92,8 +92,8 @@ func (sg *SunGrow) GetTemplateData(template string, date string, filter string) ep := sg.GetByStruct( "AppService.queryMutiPointDataList", queryMutiPointDataList.RequestData { - // PsID: api.SetIntegerValue(psId), - PsID: psId, + // PsId: api.SetIntegerValue(psId), + PsId: psId, PsKey: valueTypes.SetPsKeyValue(pointNames.PrintKeys()), Points: pointNames.PrintPoints(), MinuteInterval: "5", @@ -484,7 +484,7 @@ func (sg *SunGrow) GetRealTimeData(psKey string) error { return sg.Error } -func (sg *SunGrow) CmdDataPsDetail(psIds ...valueTypes.Integer) error { +func (sg *SunGrow) CmdDataPsDetail(psIds ...valueTypes.PsId) error { for range Only.Once { if len(psIds) == 0 { psIds, sg.Error = sg.GetPsIds() @@ -497,7 +497,7 @@ func (sg *SunGrow) CmdDataPsDetail(psIds ...valueTypes.Integer) error { data.New(sg) for _, psId := range psIds { - response := data.GetByApi("getPsDetail", SunGrowDataRequest{PsId: psId}) + response := data.GetByEndPointName("getPsDetail", SunGrowDataRequest{PsId: &psId}) if response.Error != nil { break } @@ -506,7 +506,7 @@ func (sg *SunGrow) CmdDataPsDetail(psIds ...valueTypes.Integer) error { break } - response = data.GetByApi("getPsDetailWithPsType", SunGrowDataRequest{PsId: psId}) + response = data.GetByEndPointName("getPsDetailWithPsType", SunGrowDataRequest{PsId: &psId}) if response.Error != nil { break } @@ -520,7 +520,7 @@ func (sg *SunGrow) CmdDataPsDetail(psIds ...valueTypes.Integer) error { return sg.Error } -func (sg *SunGrow) GetPointData(date string, pointNames api.TemplatePoints, psIds ...valueTypes.Integer) error { +func (sg *SunGrow) GetPointData(date string, pointNames api.TemplatePoints, psIds ...valueTypes.PsId) error { for range Only.Once { if len(pointNames) == 0 { sg.Error = errors.New("no points defined") @@ -543,7 +543,7 @@ func (sg *SunGrow) GetPointData(date string, pointNames api.TemplatePoints, psId ep := sg.GetByStruct( "AppService.queryMutiPointDataList", queryMutiPointDataList.RequestData{ - PsID: psId, + PsId: psId, PsKey: valueTypes.SetPsKeyValue(pointNames.PrintKeys()), Points: pointNames.PrintPoints(), MinuteInterval: "5", @@ -600,7 +600,7 @@ func (sg *SunGrow) SearchPointNames(pns ...string) error { ep := sg.GetByStruct( "AppService.getPowerDevicePointInfo", // getPowerDevicePointInfo.RequestData{Id: strconv.FormatInt(int64(pni), 10)}, - getPowerDevicePointInfo.RequestData{Id: valueTypes.SetIntegerValue(int64(pni)) }, + getPowerDevicePointInfo.RequestData{PsId: valueTypes.SetPsIdValue(int64(pni)) }, DefaultCacheTimeout, ) if sg.Error != nil { @@ -620,7 +620,7 @@ func (sg *SunGrow) SearchPointNames(pns ...string) error { for _, pn := range pns { ep := sg.GetByStruct( "AppService.getPowerDevicePointInfo", - getPowerDevicePointInfo.RequestData{Id: valueTypes.SetIntegerString(pn)}, + getPowerDevicePointInfo.RequestData{PsId: valueTypes.SetPsIdString(pn)}, DefaultCacheTimeout, ) if sg.Error != nil { @@ -651,7 +651,7 @@ func (sg *SunGrow) SearchPointNames(pns ...string) error { return sg.Error } -func (sg *SunGrow) GetDeviceList(psIds ...valueTypes.Integer) error { +func (sg *SunGrow) GetDeviceList(psIds ...valueTypes.PsId) error { for range Only.Once { if len(psIds) == 0 { psIds, sg.Error = sg.GetPsIds() @@ -723,7 +723,7 @@ func (sg *SunGrow) GetDeviceModelInfoList() error { return sg.Error } -func (sg *SunGrow) GetDevicePoints(psIds ...valueTypes.Integer) error { +func (sg *SunGrow) GetDevicePoints(psIds ...valueTypes.PsId) error { for range Only.Once { var points api.DataMap @@ -776,7 +776,7 @@ func (sg *SunGrow) GetDevicePoints(psIds ...valueTypes.Integer) error { // getPowerStationData // api raw getPowerStationData '{"date_id":"20221007","date_type":"1","ps_id":"1171348"}' - ep = sg.GetByStruct("AppService.getPowerStationData", getPowerStationData.RequestData{ PsId: psId, DateType: "1", DateID: "20221007"}, DefaultCacheTimeout) + ep = sg.GetByStruct("AppService.getPowerStationData", getPowerStationData.RequestData{ PsId: psId, DateType: "1", DateId: "20221007"}, DefaultCacheTimeout) if sg.Error != nil { break } @@ -789,7 +789,7 @@ func (sg *SunGrow) GetDevicePoints(psIds ...valueTypes.Integer) error { points.AppendMap(data) // api raw getPowerStationData '{"date_id":"202210","date_type":"2","ps_id":"1171348"}' - ep = sg.GetByStruct("AppService.getPowerStationData", getPowerStationData.RequestData{ PsId: psId, DateType: "2", DateID: "202210"}, DefaultCacheTimeout) + ep = sg.GetByStruct("AppService.getPowerStationData", getPowerStationData.RequestData{ PsId: psId, DateType: "2", DateId: "202210"}, DefaultCacheTimeout) if sg.Error != nil { break } @@ -802,7 +802,7 @@ func (sg *SunGrow) GetDevicePoints(psIds ...valueTypes.Integer) error { points.AppendMap(data) // api raw getPowerStationData '{"date_id":"2022","date_type":"3","ps_id":"1171348"}' - ep = sg.GetByStruct("AppService.getPowerStationData", getPowerStationData.RequestData{ PsId: psId, DateType: "3", DateID: "2022"}, DefaultCacheTimeout) + ep = sg.GetByStruct("AppService.getPowerStationData", getPowerStationData.RequestData{ PsId: psId, DateType: "3", DateId: "2022"}, DefaultCacheTimeout) if sg.Error != nil { break } @@ -834,7 +834,7 @@ func (sg *SunGrow) GetDevicePoints(psIds ...valueTypes.Integer) error { // api get getHouseholdStoragePsReport '{"date_id":"20221001","date_type":"1","ps_id":"1129147"}' ep = sg.GetByStruct( "AppService.getHouseholdStoragePsReport", - getHouseholdStoragePsReport.RequestData{ DateID: "20221001", DateType: "1", PsId: psId }, + getHouseholdStoragePsReport.RequestData{ DateId: "20221001", DateType: "1", PsId: psId }, DefaultCacheTimeout, ) if sg.Error != nil { @@ -947,11 +947,11 @@ func PrintPause(index int, max int) { } } -func (sg *SunGrow) GetPointName(psIds valueTypes.Integer) error { +func (sg *SunGrow) GetPointName(psId valueTypes.PsId) error { for range Only.Once { ep := sg.GetByStruct( "AppService.getPowerDevicePointInfo", - getPowerDevicePointInfo.RequestData{Id: psIds}, + getPowerDevicePointInfo.RequestData{PsId: psId}, DefaultCacheTimeout, ) if sg.Error != nil { @@ -968,7 +968,7 @@ func (sg *SunGrow) GetPointName(psIds valueTypes.Integer) error { // table2 := data.GetEndPointData() // fmt.Printf("%v\n", table2) - table.SetTitle("Point Name %s", psIds) + table.SetTitle("Point Name %s", psId) table.SetFilePrefix(data.SetFilenamePrefix("")) table.SetGraphFilter("") table.SetSaveFile(sg.SaveAsFile) @@ -983,8 +983,8 @@ func (sg *SunGrow) GetPointName(psIds valueTypes.Integer) error { } -func (sg *SunGrow) GetPsIds() ([]valueTypes.Integer, error) { - var ret []valueTypes.Integer +func (sg *SunGrow) GetPsIds() ([]valueTypes.PsId, error) { + var ret []valueTypes.PsId for range Only.Once { ep := sg.GetByStruct("AppService.getPsList", nil, DefaultCacheTimeout) @@ -1000,8 +1000,8 @@ func (sg *SunGrow) GetPsIds() ([]valueTypes.Integer, error) { return ret, sg.Error } -func (sg *SunGrow) GetPsId() (valueTypes.Integer, error) { - var ret valueTypes.Integer +func (sg *SunGrow) GetPsId() (valueTypes.PsId, error) { + var ret valueTypes.PsId for range Only.Once { @@ -1023,15 +1023,15 @@ func (sg *SunGrow) GetPsId() (valueTypes.Integer, error) { return ret, sg.Error } -func (sg *SunGrow) StringToPids(pids ...string) ([]valueTypes.Integer, error) { - var psIds []valueTypes.Integer +func (sg *SunGrow) StringToPids(pids ...string) ([]valueTypes.PsId, error) { + var psIds []valueTypes.PsId for range Only.Once { for _, pid := range pids { // p, err := strconv.ParseInt(pid, 10, 64) // if err != nil { // continue // } - psIds = append(psIds, valueTypes.SetIntegerString(pid)) + psIds = append(psIds, valueTypes.SetPsIdString(pid)) } if len(psIds) == 0 { psIds, sg.Error = sg.GetPsIds() @@ -1077,15 +1077,15 @@ func (sg *SunGrow) GetDevices(print bool) (getDeviceList.Devices, error) { for _, psId := range psIds { ret = append(ret, getDeviceList.Device{ Vendor: valueTypes.SetStringValue(""), - PsId: psId.PsID, - PsKey: valueTypes.SetPsKeyValue(psId.PsID.String()), + PsId: psId.PsId, + PsKey: valueTypes.SetPsKeyValue(psId.PsId.String()), DeviceName: psId.PsName, DeviceProSn: psId.PsShortName, DeviceModel: valueTypes.SetStringValue(""), DeviceType: psId.PsType, DeviceCode: valueTypes.SetIntegerValue(0), ChannelId: valueTypes.SetIntegerValue(0), - DeviceModelID: valueTypes.SetIntegerValue(0), + DeviceModelId: valueTypes.SetIntegerValue(0), TypeName: valueTypes.SetStringValue("Ps Id"), DeviceState: psId.PsHealthStatus, DevStatus: psId.PsStatus, @@ -1094,7 +1094,7 @@ func (sg *SunGrow) GetDevices(print bool) (getDeviceList.Devices, error) { // PsFaultStatus: d.PsFaultStatus, // PsHealthStatus: d.PsHealthStatus, // PsHolder: d.PsHolder, - // PsID: d.PsID, + // PsId: d.PsId, // PsName: d.PsName, // PsShortName: d.PsShortName, // PsStatus: d.PsStatus, @@ -1104,7 +1104,7 @@ func (sg *SunGrow) GetDevices(print bool) (getDeviceList.Devices, error) { ep = sg.GetByStruct( "AppService.getDeviceList", // getDeviceList.RequestData{PsId: strconv.FormatInt(psId, 10)}, - getDeviceList.RequestData{PsId: psId.PsID}, + getDeviceList.RequestData{PsId: psId.PsId}, DefaultCacheTimeout, ) if sg.Error != nil { @@ -1138,7 +1138,7 @@ func (sg *SunGrow) GetPsModels() ([]string, error) { var ret []string for range Only.Once { - var psIds []valueTypes.Integer + var psIds []valueTypes.PsId psIds, sg.Error = sg.StringToPids() if sg.Error != nil { break @@ -1167,7 +1167,7 @@ func (sg *SunGrow) GetPsSerials() ([]string, error) { var ret []string for range Only.Once { - var psIds []valueTypes.Integer + var psIds []valueTypes.PsId psIds, sg.Error = sg.StringToPids() if sg.Error != nil { break @@ -1196,7 +1196,7 @@ func (sg *SunGrow) GetPsKeys() ([]string, error) { var ret []string for range Only.Once { - var psIds []valueTypes.Integer + var psIds []valueTypes.PsId psIds, sg.Error = sg.StringToPids() if sg.Error != nil { break diff --git a/iSolarCloud/struct.go b/iSolarCloud/struct.go index 18af6d4d0..b3e23ffd3 100644 --- a/iSolarCloud/struct.go +++ b/iSolarCloud/struct.go @@ -117,9 +117,7 @@ func (sg *SunGrow) GetByJson(endpoint string, request string) api.EndPoint { sg.Error = ret.GetError() if sg.Error != nil { if strings.Contains(sg.Error.Error(), "er_token_login_invalid") { - _ = sg.ApiRoot.WebCacheRemove(sg.Auth) - _ = sg.Auth.RemoveToken() - // _ = sg.Auth.ApiRemoveDataFile() + sg.Logout() break } } @@ -192,9 +190,8 @@ func (sg *SunGrow) GetByStruct(endpoint string, request interface{}, cache time. sg.Error = ret.GetError() if strings.Contains(sg.Error.Error(), "er_token_login_invalid") { - _ = sg.ApiRoot.WebCacheRemove(sg.Auth) - _ = sg.Auth.RemoveToken() - // _ = sg.Auth.ApiRemoveDataFile() + sg.Logout() + break } } @@ -285,6 +282,14 @@ func (sg *SunGrow) Login(auth login.SunGrowAuth) error { return sg.Error } +func (sg *SunGrow) Logout() { + for range Only.Once { + _ = sg.ApiRoot.WebCacheRemove(sg.Auth) + _ = sg.Auth.RemoveToken() + // _ = sg.Auth.ApiRemoveDataFile() + } +} + func (sg *SunGrow) GetToken() string { return sg.Auth.Token() } diff --git a/mmHa/struct.go b/mmHa/struct.go index ef7d56579..4d7fa7b40 100644 --- a/mmHa/struct.go +++ b/mmHa/struct.go @@ -29,7 +29,7 @@ type Mqtt struct { clientOptions *mqtt.ClientOptions LastRefresh time.Time `json:"-"` SungrowDevices getDeviceList.Devices `json:"-"` - SungrowPsIds map[valueTypes.Integer]bool + SungrowPsIds map[valueTypes.PsId]bool DeviceName string MqttDevices map[string]Device @@ -63,7 +63,7 @@ func New(req Mqtt) *Mqtt { ret.binarySensorPrefix = "homeassistant/binary_sensor/" + req.ClientId ret.MqttDevices = make(map[string]Device) - ret.SungrowPsIds = make(map[valueTypes.Integer]bool) + ret.SungrowPsIds = make(map[valueTypes.PsId]bool) } return &ret