first overflow service commit
This commit is contained in:
65
proxy/sensorItemMapping/sensorItemMapping.go
Normal file
65
proxy/sensorItemMapping/sensorItemMapping.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package sensorItemMapping
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"git.loafle.net/overflow/commons_go/model/timestamp"
|
||||
"git.loafle.net/overflow/overflow_proxy_service/proxy/sensor"
|
||||
"git.loafle.net/overflow/overflow_proxy_service/proxy/sensorItem"
|
||||
"git.loafle.net/overflow/overflow_proxy_service/proxy/utils"
|
||||
)
|
||||
|
||||
type SensorItemMapping struct {
|
||||
Id json.Number `json:"id,Number,omitempty"`
|
||||
Sensor sensor.Sensor `json:"sensor,omitempty"`
|
||||
SensorItem sensorItem.SensorItem `json:"sensorItem,omitempty"`
|
||||
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
||||
}
|
||||
|
||||
type SensorItemMappingService struct {
|
||||
}
|
||||
|
||||
func NewSensorItemMappingService() *SensorItemMappingService {
|
||||
return &SensorItemMappingService{}
|
||||
}
|
||||
|
||||
func (sims *SensorItemMappingService) Create(sim *SensorItemMapping) (string, error) {
|
||||
out, err := utils.InvokeDBByModel("sensorItemMapping", "create", sim, "com.loafle.overflow.sensor.model.SensorItemMapping")
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (sims *SensorItemMappingService) CreateAll(siml *[]*SensorItemMapping) (string, error) {
|
||||
|
||||
outlist := make([]string, 0)
|
||||
for _, sim := range *siml {
|
||||
out,err := sims.Create(sim)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
outlist = append(outlist, out)
|
||||
}
|
||||
|
||||
bytes,err := json.Marshal(outlist)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(bytes), nil
|
||||
|
||||
}
|
||||
|
||||
func (ss *SensorItemMappingService) List(s *sensor.Sensor) (string, error) {
|
||||
|
||||
out, err := utils.InvokeDBByModel("sensorItemMapping", "findAllBySensorId", s, "com.loafle.overflow.sensor.model.Sensor")
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return out, nil
|
||||
|
||||
}
|
||||
60
proxy/sensorItemMapping/sensorItemMapping_test.go
Normal file
60
proxy/sensorItemMapping/sensorItemMapping_test.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package sensorItemMapping
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"git.loafle.net/overflow/overflow_proxy_service/proxy/sensor"
|
||||
"testing"
|
||||
"fmt"
|
||||
"sync"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func TestSensorItemMappingService_List(t *testing.T) {
|
||||
s := &sensor.Sensor{}
|
||||
s.Id = json.Number("1")
|
||||
|
||||
sims := NewSensorItemMappingService()
|
||||
res, _ := sims.List(s)
|
||||
|
||||
t.Log(res)
|
||||
}
|
||||
|
||||
|
||||
func TestSensorItemMappingService_List_GoRutine(t *testing.T) {
|
||||
//s := &sensor.Sensor{}
|
||||
//s.Id = json.Number("14")
|
||||
|
||||
sims := NewSensorItemMappingService()
|
||||
|
||||
il := make([]int, 0)
|
||||
|
||||
il = append(il, 1)
|
||||
il = append(il, 2)
|
||||
il = append(il, 3)
|
||||
il = append(il, 13)
|
||||
il = append(il, 14)
|
||||
|
||||
for _, ii := range il {
|
||||
|
||||
|
||||
go func(i int) {
|
||||
s := &sensor.Sensor{}
|
||||
s.Id = json.Number(strconv.Itoa(ii))
|
||||
res, _ := sims.List(s)
|
||||
fmt.Print(res)
|
||||
}(ii)
|
||||
|
||||
|
||||
}
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
|
||||
wg.Add(1)
|
||||
|
||||
|
||||
wg.Wait()
|
||||
|
||||
//res, _ := sims.List(s)
|
||||
//
|
||||
//t.Log(res)
|
||||
}
|
||||
Reference in New Issue
Block a user