package NatsServer import ( "encoding/json" "errors" powerlibs "git.baozhida.cn/ERP_libs/Power" userlibs "git.baozhida.cn/ERP_libs/User" "github.com/vmihailenco/msgpack/v5" "time" ) // 验证TOKEY func (m *NatsImpl) Verification(GetCookie string, GetString string) (userlibs.User, error) { var user userlibs.User User_tokey := GetCookie if len(User_tokey) == 0 { User_tokey = GetString } if len(User_tokey) == 0 { return user, errors.New("user tokey is null") } // 请求-响应, 向 verification 发布一个 `ToKey` 请求数据,设置超时间3秒,如果有多个响应,只接收第一个收到的消息 msg, err := m.nats.Request(m.NatsSubj_Prefix+"ERP_User_verification", []byte(User_tokey), 3*time.Second) if err != nil { return user, err } type T_R struct { Code int16 `xml:"Code"` Msg string `xml:"Msg"` Data userlibs.User `xml:"Data"` // 泛型 } var t_R T_R err = msgpack.Unmarshal(msg.Data, &t_R) if err != nil { return user, err } if t_R.Code != 200 { return user, errors.New(t_R.Msg) } return t_R.Data, nil } func (m *NatsImpl) Read_User_List_All() (list []userlibs.User, err error) { msg, err := m.nats.Request(m.NatsSubj_Prefix+"ERP_User_Read_User_List_All", []byte(""), 3*time.Second) if err != nil { return list, err } type T_R struct { Code int16 `xml:"Code"` Msg string `xml:"Msg"` Data []userlibs.User `xml:"Data"` } var t_R T_R err = msgpack.Unmarshal(msg.Data, &t_R) if err != nil { return list, err } if t_R.Code != 200 { return list, errors.New(t_R.Msg) } return t_R.Data, nil } func (m *NatsImpl) Read_User_List_T_uuid(T_name string, T_uuid_list []string, page, page_z int) (list []userlibs.User, cnt int64, err error) { type T_S struct { T_uuid []string T_name string Page int Page_z int } b, _ := msgpack.Marshal(&T_S{T_uuid: T_uuid_list, T_name: T_name, Page: page, Page_z: page_z}) msg, err := m.nats.Request(m.NatsSubj_Prefix+"ERP_User_Read_User_List_T_uuid", b, 3*time.Second) if err != nil { return list, cnt, err } type T_R struct { Code int16 `xml:"Code"` Msg string `xml:"Msg"` Data []userlibs.User `xml:"Data"` Num int64 `xml:"Num"` } var t_R T_R err = msgpack.Unmarshal(msg.Data, &t_R) if err != nil { return list, cnt, err } if t_R.Code != 200 { return list, cnt, errors.New(t_R.Msg) } return t_R.Data, t_R.Num, nil } func (m *NatsImpl) Read_Power_List_All() (list []powerlibs.Power_R, err error) { msg, err := m.nats.Request(m.NatsSubj_Prefix+"ERP_User_Read_Power_List_All", []byte(""), 3*time.Second) if err != nil { return list, err } type T_R struct { Code int16 `xml:"Code"` Msg string `xml:"Msg"` Data []powerlibs.Power_R `xml:"Data"` // 泛型 } var t_R T_R err = msgpack.Unmarshal(msg.Data, &t_R) if err != nil { return list, err } if t_R.Code != 200 { return list, errors.New(t_R.Msg) } return t_R.Data, nil } // 添加系统日志 func (m *NatsImpl) AddSysLogs(T_class, T_title string, T_txt interface{}) { jsonStu, _ := json.Marshal(T_txt) type T_S struct { T_class string T_title string T_txt string } b, _ := msgpack.Marshal(&T_S{T_class: T_class, T_title: T_title, T_txt: string(jsonStu)}) // 发布-订阅 模式,向 test1 发布一个 `Hello World` 数据 _ = m.nats.Publish(m.NatsSubj_Prefix+"ERP_AddSysLogs", b) } // 添加用户日志 func (m *NatsImpl) AddUserLogs(T_uuid, T_class, T_title string, T_txt interface{}) { jsonStu, _ := json.Marshal(T_txt) type T_S struct { T_uuid string T_class string T_title string T_txt string } b, _ := msgpack.Marshal(&T_S{T_uuid: T_uuid, T_class: T_class, T_title: T_title, T_txt: string(jsonStu)}) // 发布-订阅 模式,向 test1 发布一个 `Hello World` 数据 _ = m.nats.Publish(m.NatsSubj_Prefix+"ERP_AddUserLogs", b) } // 添加用户日志 func (m *NatsImpl) AddNews(T_uuid, T_title, T_Url string) { type T_S struct { T_uuid string T_Title string T_Url string } b, _ := msgpack.Marshal(&T_S{T_uuid: T_uuid, T_Title: T_title, T_Url: T_Url}) // 发布-订阅 模式,向 test1 发布一个 `Hello World` 数据 _ = m.nats.Publish(m.NatsSubj_Prefix+"ERP_AddNews", b) }