123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- 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
- }
|