69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
package agent
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"git.loafle.net/overflow/overflow_proxy_service/proxy"
|
|
"git.loafle.net/overflow/overflow_proxy_service/proxy/member"
|
|
"time"
|
|
)
|
|
|
|
type AgentService struct {
|
|
}
|
|
|
|
type Agent struct {
|
|
Id json.Number `json:"id,Number,omitempty"`
|
|
AuthorizedDate int64 `json:"authorizedDate,Number,omitempty"`
|
|
Description string `json:"description,omitempty"`
|
|
Member member.Member `json:"member,omitempty"`
|
|
LastPollingDate int64 `json:"description,omitempty"`
|
|
Status string `json:"status,omitempty"`
|
|
}
|
|
|
|
func NewAgentService() *AgentService {
|
|
return &AgentService{}
|
|
}
|
|
|
|
func NewAgent(desc string, member member.Member) *Agent {
|
|
|
|
na := &Agent{
|
|
AuthorizedDate: time.Now().Unix(),
|
|
Description: desc,
|
|
Member: member,
|
|
}
|
|
return na
|
|
}
|
|
|
|
func (as *AgentService) SaveAgent(agent *Agent) (string, error) {
|
|
bytes, err := json.Marshal(agent)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
fmt.Println(agent.Member.Id)
|
|
fmt.Println(string(bytes))
|
|
paramMap := make(map[string]string)
|
|
paramMap["com.loafle.overflow.agent.model.Agent"] = string(bytes)
|
|
|
|
out := proxy.InvokeDB("agent", "create", paramMap)
|
|
|
|
return out, nil
|
|
}
|
|
|
|
func (as *AgentService) getAgentList(memberId string) (string, error) {
|
|
paramMap := make(map[string]string)
|
|
|
|
mem := member.NewMember()
|
|
mem.Id = json.Number(memberId)
|
|
|
|
bytes, err := json.Marshal(mem)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
paramMap["com.loafle.overflow.member.model.Member"] = string(bytes)
|
|
|
|
out := proxy.InvokeDB("agent", "findAgentListByMemberId", paramMap)
|
|
|
|
return out, nil
|
|
}
|