package NatsServer import ( "ERP_user/Nats" "ERP_user/conf" "ERP_user/logs" "ERP_user/models/Account" "errors" "fmt" "github.com/vmihailenco/msgpack/v5" menulibs "gogs.baozhida.cn/zoie/ERP_libs/Menu" powerlibs "gogs.baozhida.cn/zoie/ERP_libs/Power" "gogs.baozhida.cn/zoie/ERP_libs/lib" "time" ) func ERP_Read_Menu_List(prefix string) ([]menulibs.Menu, error) { sysName := Account.Get_Sys_Name(prefix) subj := conf.NatsSubj_Prefix + fmt.Sprintf("%s_%s", prefix, "Read_Menu_List") msg, err := Nats.Nats.Request(subj, []byte(""), 3*time.Second) if err != nil { logs.Error(lib.FuncName(), sysName, err) return nil, err } type T_R struct { Code int16 `xml:"Code"` Msg string `xml:"Msg"` Data []menulibs.Menu `xml:"Data"` // 泛型 } var t_R T_R err = msgpack.Unmarshal(msg.Data, &t_R) if err != nil { logs.Error(lib.FuncName(), sysName, err) return nil, err } fmt.Printf("%s: %+v\n", subj, t_R) return t_R.Data, nil } func ERP_Read_User_Bind_Menu_List(prefix string, T_power string) ([]menulibs.Menu, error) { sysName := Account.Get_Sys_Name(prefix) subj := conf.NatsSubj_Prefix + fmt.Sprintf("%s_%s", prefix, "Read_User_Bind_Menu_List") msg, err := Nats.Nats.Request(subj, []byte(T_power), 3*time.Second) if err != nil { logs.Error(lib.FuncName(), sysName, err) return nil, err } type T_R struct { Code int16 `xml:"Code"` Msg string `xml:"Msg"` Data []menulibs.Menu `xml:"Data"` // 泛型 } var t_R T_R err = msgpack.Unmarshal(msg.Data, &t_R) if err != nil { logs.Error(lib.FuncName(), sysName, err) return nil, err } fmt.Printf("%s: %+v\n", subj, t_R) return t_R.Data, nil } func ERP_Add_Power(prefix string, power powerlibs.Power) (id int, err error) { sysName := Account.Get_Sys_Name(prefix) subj := conf.NatsSubj_Prefix + fmt.Sprintf("%s_%s", prefix, "Add_Power") b, _ := msgpack.Marshal(&power) msg, err := Nats.Nats.Request(subj, b, 3*time.Second) if err != nil { logs.Error(lib.FuncName(), sysName, err) return id, err } type T_R struct { Code int16 `xml:"Code"` Msg string `xml:"Msg"` Data int64 `xml:"Data"` // 泛型 } var t_R T_R err = msgpack.Unmarshal(msg.Data, &t_R) if err != nil { logs.Error(lib.FuncName(), sysName, err) return } fmt.Printf("%s: %+v\n", subj, t_R) if t_R.Code != 200 { err = errors.New(t_R.Msg) logs.Error(lib.FuncName(), sysName, err) return id, err } return int(t_R.Data), nil } func ERP_Read_Power_ByT_id(prefix string, T_id string) (r powerlibs.Power, err error) { sysName := Account.Get_Sys_Name(prefix) subj := conf.NatsSubj_Prefix + fmt.Sprintf("%s_%s", prefix, "Read_Power_ByT_id") msg, err := Nats.Nats.Request(subj, []byte(T_id), 3*time.Second) if err != nil { logs.Error(lib.FuncName(), sysName, err) return } type T_R struct { Code int16 `xml:"Code"` Msg string `xml:"Msg"` Data powerlibs.Power `xml:"Data"` // 泛型 } var t_R T_R err = msgpack.Unmarshal(msg.Data, &t_R) if err != nil { logs.Error(lib.FuncName(), sysName, err) return } fmt.Printf("%s: %+v\n", subj, t_R) if t_R.Code != 200 { err = errors.New(t_R.Msg) logs.Error(lib.FuncName(), sysName, err) return r, err } return t_R.Data, nil } func ERP_Update_Power(prefix string, power powerlibs.Power) (id int, err error) { sysName := Account.Get_Sys_Name(prefix) subj := conf.NatsSubj_Prefix + fmt.Sprintf("%s_%s", prefix, "Update_Power") b, _ := msgpack.Marshal(&power) msg, err := Nats.Nats.Request(subj, b, 3*time.Second) if err != nil { logs.Error(lib.FuncName(), sysName, err) return id, err } type T_R struct { Code int16 `xml:"Code"` Msg string `xml:"Msg"` Data int `xml:"Data"` // 泛型 } var t_R T_R err = msgpack.Unmarshal(msg.Data, &t_R) if err != nil { logs.Error(lib.FuncName(), sysName, err) return } fmt.Printf("%s: %+v\n", subj, t_R) if t_R.Code != 200 { err = errors.New(t_R.Msg) logs.Error(lib.FuncName(), sysName, err) return id, err } return t_R.Data, nil } func ERP_Delete_Power(prefix string, power powerlibs.Power) (id int64, err error) { sysName := Account.Get_Sys_Name(prefix) subj := conf.NatsSubj_Prefix + fmt.Sprintf("%s_%s", prefix, "Delete_Power") b, _ := msgpack.Marshal(&power) msg, err := Nats.Nats.Request(subj, b, 3*time.Second) if err != nil { logs.Error(lib.FuncName(), sysName, err) return id, err } type T_R struct { Code int16 `xml:"Code"` Msg string `xml:"Msg"` Data int64 `xml:"Data"` // 泛型 } var t_R T_R err = msgpack.Unmarshal(msg.Data, &t_R) if err != nil { logs.Error(lib.FuncName(), sysName, err) return } fmt.Printf("%s: %+v\n", subj, t_R) if t_R.Code != 200 { err = errors.New(t_R.Msg) logs.Error(lib.FuncName(), sysName, err) return id, err } return t_R.Data, nil }