123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- 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)
- }
|