水电表接口更新
水电表接口版本更新为v0.0.8
vuuvv.cn/youku/meter-api v0.0.8
使用方法
import (
"vuuvv.cn/youku/meter-api/requests"
)
func TestGetOrCreate(t *testing.T) {
setup()
ret, err := requests.Meter.GetOrCreate(&forms.Meter{
OrgId: 7484297549185024,
Brand: "ytl",
Type: "electricity",
Sn: "1234567",
Name: "1234567",
})
if err != nil {
t.Fatal(err)
return
}
t.Log(ret)
}
// 接口中还有 GetById, GetBySn, Delete, GetOrCreate, Current, Clear, Toggle可以自行查看源码并调用
水电表的创建将增加mac字段
// vuuvv.cn/youku/meter-api/forms/meter.go
type Meter struct {
orm.Id
OrgId int64 `json:"orgId" valid:"required~请指定所属机构/园区"`
Type string `json:"type" valid:"required~请选择设备类型"`
Brand string `json:"brand" valid:"required~请选择设备厂商"`
Name string `json:"name"`
Mac string `json:"mac" valid:"required~请填写设备MAC地址"`
Sn string `json:"sn" valid:"required~请填写设备序列号"`
PayAccountId int64 `json:"payAccountId"`
PriceId int64 `json:"priceId"`
PriceType string `json:"priceType"`
Password string `json:"password"`
MinBalance int `json:"minBalance"`
Lng string `json:"lng"`
Lat string `json:"lat"`
Address string `json:"address"`
AreaCode string `json:"areaCode"`
State int `json:"state"`
Data datatypes.JSON `json:"data"`
RawData *entity.PileData `json:"rawData"`
Coords *datatypes.GisCoordinate `json:"-"`
}
创建的时候最好保存Id,用以查询和删除
因为增加了mac字段,所以上游删除的时候也要调用本接口进行删除
// vuuvv.cn/youku/meter-api/requests/meter.go
type meterRequest struct {
}
var Meter = &meterRequest{}
// GetById 以Id获取水电表
func (s *meterRequest) GetById(id int64) (ret *entity.Meter, err error) {
ret = &entity.Meter{}
_, err = request.GetService(
ServiceNameMeter,
"/meter/detail",
map[string]string{"id": strconv.FormatInt(id, 10)},
ret,
)
return ret, err
}
// GetBySn 以Id获取水电表
func (s *meterRequest) GetBySn(sn string) (ret *entity.Meter, err error) {
ret = &entity.Meter{}
_, err = request.GetService(
ServiceNameMeter,
"/meter/detail",
map[string]string{"sn": sn},
ret,
)
return ret, err
}
// Delete 删除水电表
func (s *meterRequest) Delete(ids []int64) (ret *entity.Meter, err error) {
ret = &entity.Meter{}
_, err = request.DeleteService(
ServiceNameMeter,
"/meter",
ids,
ret,
)
return ret, err
}
// GetOrCreate 如果sn存在就获取水电表, 如未找到则创建一个
func (s *meterRequest) GetOrCreate(form *forms.Meter) (ret *entity.Meter, err error) {
ret = &entity.Meter{}
_, err = request.PostService(
ServiceNameMeter,
"/meter/get_or_create",
form,
ret,
)
return ret, err
}
// Current 读取水电表度数
func (s *meterRequest) Current(sn *forms.DeviceSn) (ret *dto.DeviceResp, err error) {
ret = &dto.DeviceResp{}
_, err = request.PostService(
ServiceNameMeter,
"/meter/device/current",
sn,
ret,
)
return ret, err
}
// Clear 水电表度数清零
func (s *meterRequest) Clear(sn *forms.DeviceSn) (ret *dto.DeviceResp, err error) {
ret = &dto.DeviceResp{}
_, err = request.PostService(
ServiceNameMeter,
"/meter/device/clear",
sn,
ret,
)
return ret, err
}
// Toggle 水电表度数开/关
func (s *meterRequest) Toggle(sn *forms.Toggle) (ret *dto.DeviceResp, err error) {
ret = &dto.DeviceResp{}
_, err = request.PostService(
ServiceNameMeter,
"/meter/device/toggle",
sn,
ret,
)
return ret, err
}