作者 tangxvhui

更新

1 -appname = partner 1 +appname = partnermg
2 runmode = "${RUN_MODE||dev}" 2 runmode = "${RUN_MODE||dev}"
3 httpport = "${HTTP_PORT||8080}" 3 httpport = "${HTTP_PORT||8080}"
4 4
@@ -68,10 +68,6 @@ spec: @@ -68,10 +68,6 @@ spec:
68 value: "1" 68 value: "1"
69 - name: ERROR_BASE_CODE_MULTIPLE 69 - name: ERROR_BASE_CODE_MULTIPLE
70 value: "1000" 70 value: "1000"
71 - - name: ABILITY_SERVICE_HOST  
72 - value: "https://suplus-worth-app-gateway-dev.fjmaimaimai.com"  
73 - - name: MMM_OPEN_API_SERVICE_HOST  
74 - value: "http://mmm-open-api-dev.fjmaimaimai.com"  
75 volumes: 71 volumes:
76 - name: accesslogs 72 - name: accesslogs
77 emptyDir: {} 73 emptyDir: {}
@@ -124,7 +124,7 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi @@ -124,7 +124,7 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi
124 Account: saveUserCmd.Account, 124 Account: saveUserCmd.Account,
125 Password: defaultPwd, 125 Password: defaultPwd,
126 AdminName: saveUserCmd.Name, 126 AdminName: saveUserCmd.Name,
127 - IsUsable: saveUserCmd.IsUsable, 127 + IsUsable: true,
128 Permission: permissionBases, 128 Permission: permissionBases,
129 } 129 }
130 } 130 }
1 package models 1 package models
2 2
3 type AdminPermission struct { 3 type AdminPermission struct {
4 - tableName struct{} `pg:"admin_permisssion"` 4 + tableName struct{} `pg:"admin_permission"`
5 //id 5 //id
6 Id int `pg:",pk"` 6 Id int `pg:",pk"`
7 //权限名称、菜单名称 7 //权限名称、菜单名称
@@ -22,7 +22,7 @@ type AdminUser struct { @@ -22,7 +22,7 @@ type AdminUser struct {
22 //是否是默认账号 22 //是否是默认账号
23 IsDefault bool `pg:",use_zero"` 23 IsDefault bool `pg:",use_zero"`
24 //账号是否可用 24 //账号是否可用
25 - IsUsable bool 25 + IsUsable bool `pg:",use_zero"`
26 //用户的权限 26 //用户的权限
27 Permission []domain.AdminPermissionBase 27 Permission []domain.AdminPermissionBase
28 28
@@ -45,7 +45,7 @@ func (reponsitory AdminUserRepository) FindOne(queryOption domain.AdminUserFindO @@ -45,7 +45,7 @@ func (reponsitory AdminUserRepository) FindOne(queryOption domain.AdminUserFindO
45 query = query.Where("id=?", queryOption.AdminUserId) 45 query = query.Where("id=?", queryOption.AdminUserId)
46 } 46 }
47 if len(queryOption.AccountEqual) > 0 { 47 if len(queryOption.AccountEqual) > 0 {
48 - query = query.Where("admin_account=?", queryOption.AccountEqual) 48 + query = query.Where("account=?", queryOption.AccountEqual)
49 } 49 }
50 err := query.First() 50 err := query.First()
51 if err != nil { 51 if err != nil {
@@ -29,7 +29,7 @@ func (mytoken *MyToken) CreateJWTToken() (string, error) { @@ -29,7 +29,7 @@ func (mytoken *MyToken) CreateJWTToken() (string, error) {
29 mytoken.StandardClaims = jwt.StandardClaims{ 29 mytoken.StandardClaims = jwt.StandardClaims{
30 NotBefore: nowTime, 30 NotBefore: nowTime,
31 IssuedAt: nowTime, 31 IssuedAt: nowTime,
32 - ExpiresAt: JWtExpiresSecond, 32 + ExpiresAt: nowTime + JWtExpiresSecond,
33 Issuer: "mmm_partnermg", 33 Issuer: "mmm_partnermg",
34 } 34 }
35 35
1 package log 1 package log
2 2
3 import ( 3 import (
4 - "github.com/astaxie/beego"  
5 "github.com/astaxie/beego/logs" 4 "github.com/astaxie/beego/logs"
6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant" 5 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant"
7 ) 6 )
8 7
9 func init() { 8 func init() {
10 logs.SetLevel(logLevel(constant.LOG_LEVEL)) 9 logs.SetLevel(logLevel(constant.LOG_LEVEL))
11 - if beego.BConfig.RunMode == "prod" {  
12 logs.SetLogFuncCall(false) 10 logs.SetLogFuncCall(false)
13 - } else {  
14 - logs.SetLogFuncCallDepth(3)  
15 - }  
16 -  
17 logs.SetLogger("file", `{"filename":"log/partnermg.log"}`) 11 logs.SetLogger("file", `{"filename":"log/partnermg.log"}`)
18 } 12 }
19 13
@@ -8,7 +8,4 @@ import ( @@ -8,7 +8,4 @@ import (
8 8
9 func init() { 9 func init() {
10 beego.InsertFilter("/*", beego.BeforeRouter, middleware.AllowCors()) 10 beego.InsertFilter("/*", beego.BeforeRouter, middleware.AllowCors())
11 - // beego.InsertFilter("/*", beego.BeforeExec, filters.CreateRequestBodyFilter())  
12 - // beego.InsertFilter("/*", beego.BeforeExec, log.CreateRequstLogFilter(Logger))  
13 - // beego.InsertFilter("/*", beego.AfterExec, log.CreateResponseLogFilter(Logger), false)  
14 } 11 }
@@ -6,10 +6,11 @@ import ( @@ -6,10 +6,11 @@ import (
6 "fmt" 6 "fmt"
7 "io/ioutil" 7 "io/ioutil"
8 "strconv" 8 "strconv"
  9 + "strings"
9 10
10 "github.com/astaxie/beego" 11 "github.com/astaxie/beego"
11 "github.com/astaxie/beego/logs" 12 "github.com/astaxie/beego/logs"
12 - "github.com/prometheus/common/log" 13 +
13 adminuserquery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/query" 14 adminuserquery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/query"
14 adminuserservice "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/service" 15 adminuserservice "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/service"
15 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" 16 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
@@ -87,30 +88,37 @@ func (controller *BaseController) Finish() { @@ -87,30 +88,37 @@ func (controller *BaseController) Finish() {
87 strByte, _ := json.Marshal(controller.Data["json"]) 88 strByte, _ := json.Marshal(controller.Data["json"])
88 length := len(strByte) 89 length := len(strByte)
89 if length > 1500 { 90 if length > 1500 {
90 - logs.Info("<====Send to client: RspBodyData: %s......", string(strByte[:1500])) 91 + logs.Info("<====Send to client: RspBodyData: ", string(strByte[:1500]))
91 } else { 92 } else {
92 - logs.Info("<====Send to client: RspBodyData: %s......", string(strByte)) 93 + logs.Info("<====Send to client: RspBodyData: ", string(strByte))
93 } 94 }
94 } 95 }
95 96
96 ////Prepare 重写 beego.Controller 的Prepare方法 97 ////Prepare 重写 beego.Controller 的Prepare方法
97 func (controller *BaseController) Prepare() { 98 func (controller *BaseController) Prepare() {
98 - log.Info("====>Recv Request:%s Method:%s", controller.Ctx.Input.URI(), controller.Ctx.Input.Method()) 99 + logs.Info("====>Recv Request:", controller.Ctx.Input.URI())
99 if controller.Ctx.Input.IsPost() || controller.Ctx.Input.IsPut() { 100 if controller.Ctx.Input.IsPost() || controller.Ctx.Input.IsPut() {
100 bodyByte, _ := ioutil.ReadAll(controller.Ctx.Request.Body) 101 bodyByte, _ := ioutil.ReadAll(controller.Ctx.Request.Body)
101 controller.Ctx.Input.SetData("requestBody", bodyByte) 102 controller.Ctx.Input.SetData("requestBody", bodyByte)
102 controller.Ctx.Request.Body.Close() 103 controller.Ctx.Request.Body.Close()
103 if len(bodyByte) > 1000 { 104 if len(bodyByte) > 1000 {
104 - log.Info("====>Recv data from client: BodyData:\n %s ...", string(bodyByte[0:1000])) 105 + logs.Info("====>Recv data from client: BodyData:\n ", string(bodyByte[0:1000]))
105 } else { 106 } else {
106 - log.Info("====>Recv data from client: BodyData: \n %s", string(bodyByte)) 107 + logs.Info("====>Recv data from client: BodyData: \n ", string(bodyByte))
107 } 108 }
108 } 109 }
109 return 110 return
110 } 111 }
111 112
112 func (controller *BaseController) GetHeaderToken() string { 113 func (controller *BaseController) GetHeaderToken() string {
113 - return controller.Ctx.Input.Header("Authorization") 114 + authString := controller.Ctx.Input.Header("Authorization")
  115 + //解出需要的jwt串 例:头Authorization:Bearer 123token456
  116 + s := strings.Split(authString, "\u0020")
  117 + var tokenString string
  118 + if len(s) > 0 {
  119 + tokenString = s[len(s)-1]
  120 + }
  121 + return tokenString
114 } 122 }
115 123
116 func (controller *BaseController) ValidJWTToken() bool { 124 func (controller *BaseController) ValidJWTToken() bool {
@@ -118,6 +126,7 @@ func (controller *BaseController) ValidJWTToken() bool { @@ -118,6 +126,7 @@ func (controller *BaseController) ValidJWTToken() bool {
118 mytoken := new(lib.MyToken) 126 mytoken := new(lib.MyToken)
119 err := mytoken.ValidJWTToken(headerToken) 127 err := mytoken.ValidJWTToken(headerToken)
120 if err != nil { 128 if err != nil {
  129 + logs.Error("校验token失败", err)
121 if mytoken.IsJwtErrorExpired(err) { 130 if mytoken.IsJwtErrorExpired(err) {
122 //token超时 131 //token超时
123 controller.Data["json"] = protocol.ResponseData{ 132 controller.Data["json"] = protocol.ResponseData{