正在显示
11 个修改的文件
包含
116 行增加
和
24 行删除
| @@ -76,6 +76,8 @@ spec: | @@ -76,6 +76,8 @@ spec: | ||
| 76 | value: "39aefef9e22744a3b2d2d3791824ae7b" | 76 | value: "39aefef9e22744a3b2d2d3791824ae7b" |
| 77 | - name: UCENTER_CHECK_ALT | 77 | - name: UCENTER_CHECK_ALT |
| 78 | value: "6DwjBO735" | 78 | value: "6DwjBO735" |
| 79 | + - name: BUSINESS_ADMIN_HOST | ||
| 80 | + value: "http://suplus-business-admin-dev.fjmaimaimai.com" | ||
| 79 | volumes: | 81 | volumes: |
| 80 | - name: accesslogs | 82 | - name: accesslogs |
| 81 | emptyDir: {} | 83 | emptyDir: {} |
| @@ -76,6 +76,8 @@ spec: | @@ -76,6 +76,8 @@ spec: | ||
| 76 | value: "39aefef9e22744a3b2d2d3791824ae7b" | 76 | value: "39aefef9e22744a3b2d2d3791824ae7b" |
| 77 | - name: UCENTER_CHECK_ALT | 77 | - name: UCENTER_CHECK_ALT |
| 78 | value: "rsF0pL!6DwjBO735" | 78 | value: "rsF0pL!6DwjBO735" |
| 79 | + - name: BUSINESS_ADMIN_HOST | ||
| 80 | + value: "http://suplus-business-admin-prd.fjmaimaimai.com" | ||
| 79 | volumes: | 81 | volumes: |
| 80 | - name: accesslogs | 82 | - name: accesslogs |
| 81 | emptyDir: {} | 83 | emptyDir: {} |
| @@ -73,6 +73,8 @@ spec: | @@ -73,6 +73,8 @@ spec: | ||
| 73 | value: "39aefef9e22744a3b2d2d3791824ae7b" | 73 | value: "39aefef9e22744a3b2d2d3791824ae7b" |
| 74 | - name: UCENTER_CHECK_ALT | 74 | - name: UCENTER_CHECK_ALT |
| 75 | value: "rsF0pL!6DwjBO735" | 75 | value: "rsF0pL!6DwjBO735" |
| 76 | + - name: BUSINESS_ADMIN_HOST | ||
| 77 | + value: "http://suplus-business-admin-test.fjmaimaimai.com" | ||
| 76 | volumes: | 78 | volumes: |
| 77 | - name: accesslogs | 79 | - name: accesslogs |
| 78 | emptyDir: {} | 80 | emptyDir: {} |
| @@ -22,7 +22,6 @@ type CompanyBase struct { | @@ -22,7 +22,6 @@ type CompanyBase struct { | ||
| 22 | AdminCompanyId int `json:"admin_company_id"` //总后台的公司id | 22 | AdminCompanyId int `json:"admin_company_id"` //总后台的公司id |
| 23 | Logo string `json:"logo"` //公司图标 | 23 | Logo string `json:"logo"` //公司图标 |
| 24 | Remarks string `json:"remarks"` //备注 | 24 | Remarks string `json:"remarks"` //备注 |
| 25 | - Status int8 `json:"status"` | ||
| 26 | Abbreviation string `json:"abbreviation"` | 25 | Abbreviation string `json:"abbreviation"` |
| 27 | } | 26 | } |
| 28 | 27 | ||
| @@ -110,9 +109,9 @@ func (service SyncCompanyService) addCompany(data CompanytData) error { | @@ -110,9 +109,9 @@ func (service SyncCompanyService) addCompany(data CompanytData) error { | ||
| 110 | Logo: data.Company.Logo, | 109 | Logo: data.Company.Logo, |
| 111 | Remarks: data.Company.Remarks, | 110 | Remarks: data.Company.Remarks, |
| 112 | AdminCompanyId: data.Company.AdminCompanyId, | 111 | AdminCompanyId: data.Company.AdminCompanyId, |
| 113 | - Status: data.Company.Status, | ||
| 114 | - Enable: domain.CompanyEnableNo, //默认初始化值 | ||
| 115 | - Abbreviation: data.Company.Abbreviation, | 112 | + //Status: data.Company.Status, |
| 113 | + Enable: domain.CompanyEnableYes, //默认初始化值 | ||
| 114 | + Abbreviation: data.Company.Abbreviation, | ||
| 116 | } | 115 | } |
| 117 | err = companyRespository.Add(&comany) | 116 | err = companyRespository.Add(&comany) |
| 118 | if err != nil { | 117 | if err != nil { |
| @@ -183,7 +182,6 @@ func (service SyncCompanyService) updateCompany(data CompanytData) error { | @@ -183,7 +182,6 @@ func (service SyncCompanyService) updateCompany(data CompanytData) error { | ||
| 183 | "Logo": data.Company.Logo, | 182 | "Logo": data.Company.Logo, |
| 184 | "Remarks": data.Company.Remarks, | 183 | "Remarks": data.Company.Remarks, |
| 185 | "AdminCompanyId": data.Company.AdminCompanyId, | 184 | "AdminCompanyId": data.Company.AdminCompanyId, |
| 186 | - "Status": data.Company.Status, | ||
| 187 | "Abbreviation": data.Company.Abbreviation, | 185 | "Abbreviation": data.Company.Abbreviation, |
| 188 | }) | 186 | }) |
| 189 | entryTime, _ := time.Parse("2006-01-02", data.User.EntryTime) | 187 | entryTime, _ := time.Parse("2006-01-02", data.User.EntryTime) |
| @@ -31,11 +31,23 @@ func (service UsersService) UserLoginBySecretKey(cmd command.LoginBySecretKeyCom | @@ -31,11 +31,23 @@ func (service UsersService) UserLoginBySecretKey(cmd command.LoginBySecretKeyCom | ||
| 31 | e := fmt.Sprintf("通过密钥(code=%s)从统一用户中心获取数据失败:%s", cmd.Code, err.Error()) | 31 | e := fmt.Sprintf("通过密钥(code=%s)从统一用户中心获取数据失败:%s", cmd.Code, err.Error()) |
| 32 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) | 32 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) |
| 33 | } | 33 | } |
| 34 | - err = loginResp.IsOK() | ||
| 35 | - if err != nil { | 34 | + |
| 35 | + if err := loginResp.IsOK(); err != nil { | ||
| 36 | e := fmt.Sprintf("登录失败:%s", err) | 36 | e := fmt.Sprintf("登录失败:%s", err) |
| 37 | return nil, lib.ThrowError(lib.BUSINESS_ERROR, e) | 37 | return nil, lib.ThrowError(lib.BUSINESS_ERROR, e) |
| 38 | } | 38 | } |
| 39 | + adminBusinessService := serviceGateway.NewMmmBusinessAdminServiceGateway() | ||
| 40 | + getUserAuthResp, err := adminBusinessService.GetUserAuth(loginResp.Data.Muid) | ||
| 41 | + if err != nil { | ||
| 42 | + e := fmt.Sprintf("用户鉴权失败:%s", err) | ||
| 43 | + return nil, lib.ThrowError(lib.BUSINESS_ERROR, e) | ||
| 44 | + } | ||
| 45 | + if err := getUserAuthResp.IsOK(); err != nil { | ||
| 46 | + return nil, lib.ThrowError(lib.BUSINESS_ERROR, "该公司没有操作权限") | ||
| 47 | + } | ||
| 48 | + if !getUserAuthResp.Data.UserAuth { | ||
| 49 | + return nil, lib.ThrowError(lib.BUSINESS_ERROR, "该公司没有操作权限") | ||
| 50 | + } | ||
| 39 | var ( | 51 | var ( |
| 40 | transactionContext, _ = factory.CreateTransactionContext(nil) | 52 | transactionContext, _ = factory.CreateTransactionContext(nil) |
| 41 | ) | 53 | ) |
| @@ -69,9 +81,6 @@ func (service UsersService) UserLoginBySecretKey(cmd command.LoginBySecretKeyCom | @@ -69,9 +81,6 @@ func (service UsersService) UserLoginBySecretKey(cmd command.LoginBySecretKeyCom | ||
| 69 | e := fmt.Sprintf("获取公司(admin_company_id=%d)数据失败:%s", loginResp.Data.CompanyId, err.Error()) | 81 | e := fmt.Sprintf("获取公司(admin_company_id=%d)数据失败:%s", loginResp.Data.CompanyId, err.Error()) |
| 70 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) | 82 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) |
| 71 | } | 83 | } |
| 72 | - if !companyData.EnableIsOk() { | ||
| 73 | - return nil, lib.ThrowError(lib.BUSINESS_ERROR, "该公司没有操作权限") | ||
| 74 | - } | ||
| 75 | //检索本系统的用户数据 | 84 | //检索本系统的用户数据 |
| 76 | usersData, err = userRespository.FindOne(domain.UsersFindOneQuery{ | 85 | usersData, err = userRespository.FindOne(domain.UsersFindOneQuery{ |
| 77 | Id: loginResp.Data.Muid, | 86 | Id: loginResp.Data.Muid, |
| @@ -14,6 +14,10 @@ var ( | @@ -14,6 +14,10 @@ var ( | ||
| 14 | UCENTER_CHECK_ALT = "rsF0pL!6DwjBO735" | 14 | UCENTER_CHECK_ALT = "rsF0pL!6DwjBO735" |
| 15 | ) | 15 | ) |
| 16 | 16 | ||
| 17 | +var ( | ||
| 18 | + BUSINESS_ADMIN_HOST = "http://suplus-business-admin-dev.fjmaimaimai.com" //企业平台的地址 | ||
| 19 | +) | ||
| 20 | + | ||
| 17 | func init() { | 21 | func init() { |
| 18 | if os.Getenv("LOG_LEVEL") != "" { | 22 | if os.Getenv("LOG_LEVEL") != "" { |
| 19 | LOG_LEVEL = os.Getenv("LOG_LEVEL") | 23 | LOG_LEVEL = os.Getenv("LOG_LEVEL") |
| @@ -31,4 +35,8 @@ func init() { | @@ -31,4 +35,8 @@ func init() { | ||
| 31 | UCENTER_CHECK_ALT = os.Getenv("UCENTER_CHECK_ALT") | 35 | UCENTER_CHECK_ALT = os.Getenv("UCENTER_CHECK_ALT") |
| 32 | } | 36 | } |
| 33 | 37 | ||
| 38 | + if os.Getenv("BUSINESS_ADMIN_HOST") != "" { | ||
| 39 | + BUSINESS_ADMIN_HOST = os.Getenv("BUSINESS_ADMIN_HOST") | ||
| 40 | + } | ||
| 41 | + | ||
| 34 | } | 42 | } |
| @@ -33,9 +33,7 @@ type Company struct { | @@ -33,9 +33,7 @@ type Company struct { | ||
| 33 | Remarks string `json:"remarks"` | 33 | Remarks string `json:"remarks"` |
| 34 | // 总后台的公司id | 34 | // 总后台的公司id |
| 35 | AdminCompanyId int `json:"adminCompanyId"` | 35 | AdminCompanyId int `json:"adminCompanyId"` |
| 36 | - // 状态 1正常 2禁用 | ||
| 37 | - Status int8 `json:"status"` | ||
| 38 | - //是否开启机会模块,是否有效【1:有效】【2:无效】 | 36 | + //是否有效【1:有效】【2:无效】 |
| 39 | Enable int8 `json:"enable"` | 37 | Enable int8 `json:"enable"` |
| 40 | // 创建时间 | 38 | // 创建时间 |
| 41 | CreateAt time.Time `json:"createAt"` | 39 | CreateAt time.Time `json:"createAt"` |
| @@ -45,9 +43,9 @@ type Company struct { | @@ -45,9 +43,9 @@ type Company struct { | ||
| 45 | DeleteAt time.Time `json:"deleteAt"` | 43 | DeleteAt time.Time `json:"deleteAt"` |
| 46 | } | 44 | } |
| 47 | 45 | ||
| 48 | -func (c Company) StatusIsOk() bool { | ||
| 49 | - return c.Status == companyStatusUsable | ||
| 50 | -} | 46 | +// func (c Company) StatusIsOk() bool { |
| 47 | +// return c.Status == companyStatusUsable | ||
| 48 | +// } | ||
| 51 | 49 | ||
| 52 | func (c Company) EnableIsOk() bool { | 50 | func (c Company) EnableIsOk() bool { |
| 53 | return c.Enable == CompanyEnableYes | 51 | return c.Enable == CompanyEnableYes |
| @@ -72,9 +70,6 @@ func (c *Company) Update(m map[string]interface{}) error { | @@ -72,9 +70,6 @@ func (c *Company) Update(m map[string]interface{}) error { | ||
| 72 | if v, ok := m["Remarks"]; ok { | 70 | if v, ok := m["Remarks"]; ok { |
| 73 | c.Remarks = fmt.Sprint(v) | 71 | c.Remarks = fmt.Sprint(v) |
| 74 | } | 72 | } |
| 75 | - if v, ok := m["Status"]; ok { | ||
| 76 | - c.Status = v.(int8) | ||
| 77 | - } | ||
| 78 | if v, ok := m["Enable"]; ok { | 73 | if v, ok := m["Enable"]; ok { |
| 79 | c.Enable = v.(int8) | 74 | c.Enable = v.(int8) |
| 80 | } | 75 | } |
| @@ -25,7 +25,7 @@ type Company struct { | @@ -25,7 +25,7 @@ type Company struct { | ||
| 25 | // 总后台的公司id | 25 | // 总后台的公司id |
| 26 | AdminCompanyId int | 26 | AdminCompanyId int |
| 27 | // 状态 1正常 2禁用 | 27 | // 状态 1正常 2禁用 |
| 28 | - Status int8 | 28 | + //Status int8 |
| 29 | //是否开启机会模块,是否有效【1:有效】【2:无效】 | 29 | //是否开启机会模块,是否有效【1:有效】【2:无效】 |
| 30 | Enable int8 | 30 | Enable int8 |
| 31 | // 创建时间 | 31 | // 创建时间 |
| @@ -32,7 +32,6 @@ func (repository CompanyRepository) transformPgModelToDomainModel(m *models.Comp | @@ -32,7 +32,6 @@ func (repository CompanyRepository) transformPgModelToDomainModel(m *models.Comp | ||
| 32 | Logo: m.Logo, | 32 | Logo: m.Logo, |
| 33 | Remarks: m.Remarks, | 33 | Remarks: m.Remarks, |
| 34 | AdminCompanyId: m.AdminCompanyId, | 34 | AdminCompanyId: m.AdminCompanyId, |
| 35 | - Status: m.Status, | ||
| 36 | Enable: m.Enable, | 35 | Enable: m.Enable, |
| 37 | CreateAt: m.CreateAt, | 36 | CreateAt: m.CreateAt, |
| 38 | UpdateAt: m.UpdateAt, | 37 | UpdateAt: m.UpdateAt, |
| @@ -52,7 +51,6 @@ func (reponsitory CompanyRepository) Add(m *domain.Company) error { | @@ -52,7 +51,6 @@ func (reponsitory CompanyRepository) Add(m *domain.Company) error { | ||
| 52 | Logo: m.Logo, | 51 | Logo: m.Logo, |
| 53 | Remarks: m.Remarks, | 52 | Remarks: m.Remarks, |
| 54 | AdminCompanyId: m.AdminCompanyId, | 53 | AdminCompanyId: m.AdminCompanyId, |
| 55 | - Status: m.Status, | ||
| 56 | Enable: m.Enable, | 54 | Enable: m.Enable, |
| 57 | CreateAt: m.CreateAt, | 55 | CreateAt: m.CreateAt, |
| 58 | UpdateAt: m.UpdateAt, | 56 | UpdateAt: m.UpdateAt, |
| @@ -74,7 +72,6 @@ func (reponsitory CompanyRepository) Edit(m *domain.Company) error { | @@ -74,7 +72,6 @@ func (reponsitory CompanyRepository) Edit(m *domain.Company) error { | ||
| 74 | Logo: m.Logo, | 72 | Logo: m.Logo, |
| 75 | Remarks: m.Remarks, | 73 | Remarks: m.Remarks, |
| 76 | AdminCompanyId: m.AdminCompanyId, | 74 | AdminCompanyId: m.AdminCompanyId, |
| 77 | - Status: m.Status, | ||
| 78 | Enable: m.Enable, | 75 | Enable: m.Enable, |
| 79 | CreateAt: m.CreateAt, | 76 | CreateAt: m.CreateAt, |
| 80 | DeleteAt: m.DeleteAt, | 77 | DeleteAt: m.DeleteAt, |
| 1 | +package serviceGateway | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "bytes" | ||
| 5 | + "encoding/json" | ||
| 6 | + "fmt" | ||
| 7 | + "io/ioutil" | ||
| 8 | + "net/http" | ||
| 9 | + "time" | ||
| 10 | + | ||
| 11 | + "github.com/astaxie/beego/logs" | ||
| 12 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant" | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +type MmmBusinessAdminServiceGateway struct { | ||
| 16 | + baseURL string | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +func NewMmmBusinessAdminServiceGateway() *MmmBusinessAdminServiceGateway { | ||
| 20 | + return &MmmBusinessAdminServiceGateway{ | ||
| 21 | + baseURL: constant.BUSINESS_ADMIN_HOST, | ||
| 22 | + } | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +type ResponseGetUserAuth struct { | ||
| 26 | + UCenterCommonMsg | ||
| 27 | + Data struct { | ||
| 28 | + UserAuth bool `json:"userAuth"` | ||
| 29 | + } `json:"data"` | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +func (gateway MmmBusinessAdminServiceGateway) httpDo(reqURL string, mathod string, bodyData interface{}) ([]byte, error) { | ||
| 33 | + httpclient := http.Client{ | ||
| 34 | + Timeout: 60 * time.Second, //请求超时时间60秒 | ||
| 35 | + } | ||
| 36 | + bt := &bytes.Buffer{} | ||
| 37 | + if bodyData != nil { | ||
| 38 | + enc := json.NewEncoder(bt) | ||
| 39 | + enc.Encode(bodyData) | ||
| 40 | + } | ||
| 41 | + logs.Info("====>Send To URL:%s", reqURL) | ||
| 42 | + logs.Info("====>Send To BusinessAdmin:%s", bt.String()) | ||
| 43 | + req, err := http.NewRequest(mathod, reqURL, bt) | ||
| 44 | + if err != nil { | ||
| 45 | + return nil, err | ||
| 46 | + } | ||
| 47 | + resp, err := httpclient.Do(req) | ||
| 48 | + if err != nil { | ||
| 49 | + return nil, err | ||
| 50 | + } | ||
| 51 | + defer resp.Body.Close() | ||
| 52 | + body, err := ioutil.ReadAll(resp.Body) | ||
| 53 | + if err != nil { | ||
| 54 | + return nil, err | ||
| 55 | + } | ||
| 56 | + logs.Info("<====BusinessAdmin Return:%s", string(body)) | ||
| 57 | + return body, nil | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | +func (gateway MmmBusinessAdminServiceGateway) GetUserAuth(userId int64) (*ResponseGetUserAuth, error) { | ||
| 61 | + param := map[string]interface{}{} | ||
| 62 | + url := gateway.baseURL + "/auth/get-user-auth" | ||
| 63 | + byteData, err := gateway.httpDo(url, "POST", param) | ||
| 64 | + if err != nil { | ||
| 65 | + return nil, err | ||
| 66 | + } | ||
| 67 | + respData := &ResponseGetUserAuth{} | ||
| 68 | + err = json.Unmarshal(byteData, respData) | ||
| 69 | + if err != nil { | ||
| 70 | + return nil, fmt.Errorf("body data %s; err:%s", string(byteData), err) | ||
| 71 | + } | ||
| 72 | + return respData, nil | ||
| 73 | +} |
| @@ -10,6 +10,7 @@ import ( | @@ -10,6 +10,7 @@ import ( | ||
| 10 | "net/url" | 10 | "net/url" |
| 11 | "time" | 11 | "time" |
| 12 | 12 | ||
| 13 | + "github.com/astaxie/beego/logs" | ||
| 13 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant" | 14 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant" |
| 14 | ) | 15 | ) |
| 15 | 16 | ||
| @@ -59,6 +60,8 @@ func (gateway MmmUserCenterServiceGateway) httpDo(reqURL string, mathod string, | @@ -59,6 +60,8 @@ func (gateway MmmUserCenterServiceGateway) httpDo(reqURL string, mathod string, | ||
| 59 | enc := json.NewEncoder(bt) | 60 | enc := json.NewEncoder(bt) |
| 60 | enc.Encode(bodyData) | 61 | enc.Encode(bodyData) |
| 61 | } | 62 | } |
| 63 | + logs.Info("====>Send To URL:%s", reqURL) | ||
| 64 | + logs.Info("====>Send To BusinessAdmin:%s", bt.String()) | ||
| 62 | req, err := http.NewRequest(mathod, reqURL, bt) | 65 | req, err := http.NewRequest(mathod, reqURL, bt) |
| 63 | if err != nil { | 66 | if err != nil { |
| 64 | return nil, err | 67 | return nil, err |
| @@ -73,6 +76,7 @@ func (gateway MmmUserCenterServiceGateway) httpDo(reqURL string, mathod string, | @@ -73,6 +76,7 @@ func (gateway MmmUserCenterServiceGateway) httpDo(reqURL string, mathod string, | ||
| 73 | if err != nil { | 76 | if err != nil { |
| 74 | return nil, err | 77 | return nil, err |
| 75 | } | 78 | } |
| 79 | + logs.Info("<====BusinessAdmin Return:%s", string(body)) | ||
| 76 | return body, nil | 80 | return body, nil |
| 77 | } | 81 | } |
| 78 | 82 | ||
| @@ -97,7 +101,7 @@ func (gateway MmmUserCenterServiceGateway) RequestUCenterLoginBySecret(secret st | @@ -97,7 +101,7 @@ func (gateway MmmUserCenterServiceGateway) RequestUCenterLoginBySecret(secret st | ||
| 97 | "type": 3, //登录方式 固定值 | 101 | "type": 3, //登录方式 固定值 |
| 98 | "secret": url.QueryEscape(secret), //必要的转换 | 102 | "secret": url.QueryEscape(secret), //必要的转换 |
| 99 | } | 103 | } |
| 100 | - url := constant.UCENTER_HOST + "/auth/serverLogin" | 104 | + url := gateway.baseURL + "/auth/serverLogin" |
| 101 | byteData, err := gateway.httpDo(url, "POST", param) | 105 | byteData, err := gateway.httpDo(url, "POST", param) |
| 102 | if err != nil { | 106 | if err != nil { |
| 103 | return nil, err | 107 | return nil, err |
| @@ -109,3 +113,5 @@ func (gateway MmmUserCenterServiceGateway) RequestUCenterLoginBySecret(secret st | @@ -109,3 +113,5 @@ func (gateway MmmUserCenterServiceGateway) RequestUCenterLoginBySecret(secret st | ||
| 109 | } | 113 | } |
| 110 | return respData, nil | 114 | return respData, nil |
| 111 | } | 115 | } |
| 116 | + | ||
| 117 | +//企业鉴权 接口 |
-
请 注册 或 登录 后发表评论