Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/oppmg into dev
正在显示
31 个修改的文件
包含
588 行增加
和
213 行删除
@@ -29,8 +29,8 @@ log_level = "${LOG_LEVEL||debug}" | @@ -29,8 +29,8 @@ log_level = "${LOG_LEVEL||debug}" | ||
29 | ##统一用户中心相关配置 | 29 | ##统一用户中心相关配置 |
30 | ucenter_check_alt = "rsF0pL!6DwjBO735" | 30 | ucenter_check_alt = "rsF0pL!6DwjBO735" |
31 | ucenter_base_url = "http://suplus-ucenter-dev.fjmaimaimai.com" | 31 | ucenter_base_url = "http://suplus-ucenter-dev.fjmaimaimai.com" |
32 | -ucenter_app_key = "0692f2b7e8d6dbd8526579864b87e3bfbc5d5c31" | ||
33 | -ucenter_secret = "0692f2b7e8d6dbd8526579864b87e3bfbc5d5c31" | 32 | +ucenter_app_key = "39aefef9e22744a3b2d2d3791824ae7b" |
33 | +ucenter_secret = "cykbjnfqgctn" | ||
34 | # 审批流程修改 消息发布 | 34 | # 审批流程修改 消息发布 |
35 | message_publish = "audit_change" | 35 | message_publish = "audit_change" |
36 | #---自定义配置 结束---- | 36 | #---自定义配置 结束---- |
@@ -59,8 +59,15 @@ func (c *AuthController) Login() { | @@ -59,8 +59,15 @@ func (c *AuthController) Login() { | ||
59 | msg = protocol.NewReturnResponse(nil, err) | 59 | msg = protocol.NewReturnResponse(nil, err) |
60 | return | 60 | return |
61 | } | 61 | } |
62 | + err = serveauth.ResetLoginToken(logintoken) | ||
63 | + if err != nil { | ||
64 | + log.Error("token 信息记录数据库失败") | ||
65 | + } | ||
62 | err = serveauth.ResetLoginTokenRedis(logintoken) | 66 | err = serveauth.ResetLoginTokenRedis(logintoken) |
63 | - msg = protocol.NewReturnResponse(logintoken, err) | 67 | + if err != nil { |
68 | + log.Error("token 信息记录redis失败") | ||
69 | + } | ||
70 | + msg = protocol.NewReturnResponse(logintoken, nil) | ||
64 | return | 71 | return |
65 | } | 72 | } |
66 | 73 |
@@ -18,20 +18,6 @@ type BaseController struct { | @@ -18,20 +18,6 @@ type BaseController struct { | ||
18 | beego.Controller | 18 | beego.Controller |
19 | } | 19 | } |
20 | 20 | ||
21 | -func (this *BaseController) Options() { | ||
22 | - this.AllowCross() //允许跨域 | ||
23 | - this.Ctx.ResponseWriter.WriteHeader(204) | ||
24 | - this.Data["json"] = map[string]interface{}{} | ||
25 | - this.ServeJSON() | ||
26 | -} | ||
27 | - | ||
28 | -func (this *BaseController) AllowCross() { | ||
29 | - this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*") | ||
30 | - this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE") | ||
31 | - this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*") | ||
32 | - //this.Ctx.WriteString("") | ||
33 | -} | ||
34 | - | ||
35 | //Prepare 实现beego.ControllerInterface 的接口 | 21 | //Prepare 实现beego.ControllerInterface 的接口 |
36 | func (this *BaseController) Prepare() { | 22 | func (this *BaseController) Prepare() { |
37 | this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*") | 23 | this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*") |
@@ -48,7 +34,7 @@ func (this *BaseController) Prepare() { | @@ -48,7 +34,7 @@ func (this *BaseController) Prepare() { | ||
48 | 34 | ||
49 | func (this *BaseController) GetAppHead() (appHead protocol.BaseHeader) { | 35 | func (this *BaseController) GetAppHead() (appHead protocol.BaseHeader) { |
50 | appHead.AccessToken = this.Ctx.Input.Header(protocol.HeaderAccessToken) | 36 | appHead.AccessToken = this.Ctx.Input.Header(protocol.HeaderAccessToken) |
51 | - appHead.RefreshToken = this.Ctx.Input.Header(protocol.HeaderRefreshToken) | 37 | + //appHead.RefreshToken = this.Ctx.Input.Header(protocol.HeaderRefreshToken) |
52 | return | 38 | return |
53 | 39 | ||
54 | } | 40 | } |
@@ -23,10 +23,19 @@ func (c *CommonController) SelectorDepartment() { | @@ -23,10 +23,19 @@ func (c *CommonController) SelectorDepartment() { | ||
23 | defer func() { | 23 | defer func() { |
24 | c.ResposeJson(msg) | 24 | c.ResposeJson(msg) |
25 | }() | 25 | }() |
26 | + type Parameter struct { | ||
27 | + DepartmentId int64 `json:"department_id"` | ||
28 | + } | ||
29 | + var param Parameter | ||
30 | + if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
31 | + log.Error("json 解析失败 err:%s", err) | ||
32 | + msg = protocol.BadRequestParam("1") | ||
33 | + return | ||
34 | + } | ||
26 | companyid := c.GetCompanyId() | 35 | companyid := c.GetCompanyId() |
27 | - departs := servecommon.SelectorDepartment(companyid) | ||
28 | - | ||
29 | - msg = protocol.NewReturnResponse(departs, nil) | 36 | + departs := servecommon.SelectorDepartment(companyid, param.DepartmentId) |
37 | + data := protocol.ResponseListData{List: departs} | ||
38 | + msg = protocol.NewReturnResponse(data, nil) | ||
30 | return | 39 | return |
31 | } | 40 | } |
32 | 41 | ||
@@ -87,3 +96,23 @@ func (c *CommonController) SelectorPosition() { | @@ -87,3 +96,23 @@ func (c *CommonController) SelectorPosition() { | ||
87 | msg = protocol.NewReturnResponse(departs, nil) | 96 | msg = protocol.NewReturnResponse(departs, nil) |
88 | return | 97 | return |
89 | } | 98 | } |
99 | + | ||
100 | +func (c *CommonController) SelectorUserAndDepart() { | ||
101 | + var msg *protocol.ResponseMessage | ||
102 | + defer func() { | ||
103 | + c.ResposeJson(msg) | ||
104 | + }() | ||
105 | + type Parameter struct { | ||
106 | + DepartmentId int64 `json:"department_id"` | ||
107 | + } | ||
108 | + var param Parameter | ||
109 | + if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
110 | + log.Error("json 解析失败 err:%s", err) | ||
111 | + msg = protocol.BadRequestParam("1") | ||
112 | + return | ||
113 | + } | ||
114 | + companyid := c.GetCompanyId() | ||
115 | + departs, err := servecommon.SelectorUserAndDepartment(param.DepartmentId, companyid) | ||
116 | + msg = protocol.NewReturnResponse(departs, err) | ||
117 | + return | ||
118 | +} |
@@ -226,6 +226,37 @@ func (c *RbacController) RoleHasMenu() { | @@ -226,6 +226,37 @@ func (c *RbacController) RoleHasMenu() { | ||
226 | return | 226 | return |
227 | } | 227 | } |
228 | 228 | ||
229 | +//TODO | ||
230 | +func (c *RbacController) GetRoleMenuAll() { | ||
231 | + var msg *protocol.ResponseMessage | ||
232 | + defer func() { | ||
233 | + c.ResposeJson(msg) | ||
234 | + }() | ||
235 | + log.Info("====>") | ||
236 | + list, err := serverbac.GetRoleHasMenuAll(1, 1) | ||
237 | + msg = protocol.NewReturnResponse(list, err) | ||
238 | + return | ||
239 | +} | ||
240 | + | ||
241 | +//RoleMenuEdit 设置角色的菜单 | ||
242 | +//@router /role/menu/edit | ||
229 | func (c *RbacController) RoleMenuEdit() { | 243 | func (c *RbacController) RoleMenuEdit() { |
244 | + var msg *protocol.ResponseMessage | ||
245 | + defer func() { | ||
246 | + c.ResposeJson(msg) | ||
247 | + }() | ||
248 | + type Parameter struct { | ||
249 | + RoleId int64 `json:"role_id"` | ||
250 | + MenuIds []int64 `json:"menu_ids"` | ||
251 | + } | ||
252 | + var param Parameter | ||
253 | + if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
254 | + log.Error("json 解析失败 err:%s", err) | ||
255 | + msg = protocol.BadRequestParam("1") | ||
256 | + return | ||
257 | + } | ||
258 | + companyid := c.GetCompanyId() | ||
259 | + err := serverbac.RoleMenuEdit(companyid, param.RoleId, param.MenuIds) | ||
260 | + msg = protocol.NewReturnResponse(nil, err) | ||
230 | return | 261 | return |
231 | } | 262 | } |
@@ -19,7 +19,7 @@ var LogRequestData = func(ctx *context.Context) { | @@ -19,7 +19,7 @@ var LogRequestData = func(ctx *context.Context) { | ||
19 | log.Info("====>Recv Request:%s", ctx.Input.URI()) | 19 | log.Info("====>Recv Request:%s", ctx.Input.URI()) |
20 | hmap := map[string]string{ | 20 | hmap := map[string]string{ |
21 | protocol.HeaderAccessToken: ctx.Input.Header(protocol.HeaderAccessToken), | 21 | protocol.HeaderAccessToken: ctx.Input.Header(protocol.HeaderAccessToken), |
22 | - protocol.HeaderRefreshToken: ctx.Input.Header(protocol.HeaderRefreshToken), | 22 | + //protocol.HeaderRefreshToken: ctx.Input.Header(protocol.HeaderRefreshToken), |
23 | } | 23 | } |
24 | if ctx.Input.RequestBody != nil { | 24 | if ctx.Input.RequestBody != nil { |
25 | log.Info("====>Recv data from client:\nHeadData: %v \nBodyData: %s", hmap, string(ctx.Input.RequestBody)) | 25 | log.Info("====>Recv data from client:\nHeadData: %v \nBodyData: %s", hmap, string(ctx.Input.RequestBody)) |
@@ -38,7 +38,7 @@ var AuthToken = func(ctx *context.Context) { | @@ -38,7 +38,7 @@ var AuthToken = func(ctx *context.Context) { | ||
38 | mtoken *serveauth.MyToken | 38 | mtoken *serveauth.MyToken |
39 | ) | 39 | ) |
40 | accesstoken := ctx.Input.Header(protocol.HeaderAccessToken) | 40 | accesstoken := ctx.Input.Header(protocol.HeaderAccessToken) |
41 | - refreshToken := ctx.Input.Header(protocol.HeaderRefreshToken) | 41 | + // refreshToken := ctx.Input.Header(protocol.HeaderRefreshToken) |
42 | mtoken, err = serveauth.ValidJWTToken(accesstoken) | 42 | mtoken, err = serveauth.ValidJWTToken(accesstoken) |
43 | if accesstoken == "123456" && beego.BConfig.RunMode != "prod" { | 43 | if accesstoken == "123456" && beego.BConfig.RunMode != "prod" { |
44 | return | 44 | return |
@@ -47,14 +47,14 @@ var AuthToken = func(ctx *context.Context) { | @@ -47,14 +47,14 @@ var AuthToken = func(ctx *context.Context) { | ||
47 | storetoken, err = redisdata.GetLoginToken(mtoken.UID) | 47 | storetoken, err = redisdata.GetLoginToken(mtoken.UID) |
48 | if err != nil { | 48 | if err != nil { |
49 | log.Error("redisdata.GetLoginToken err:%s", err) | 49 | log.Error("redisdata.GetLoginToken err:%s", err) |
50 | - msg = protocol.NewMesage("10024") | 50 | + msg = protocol.NewMessage("10024") |
51 | ctx.Output.JSON(msg, false, false) | 51 | ctx.Output.JSON(msg, false, false) |
52 | return | 52 | return |
53 | } | 53 | } |
54 | if beego.BConfig.RunMode == "prod" { | 54 | if beego.BConfig.RunMode == "prod" { |
55 | //校验是否是单客户端操作 | 55 | //校验是否是单客户端操作 |
56 | if storetoken.AccessToken != accesstoken { | 56 | if storetoken.AccessToken != accesstoken { |
57 | - msg = protocol.NewMesage("10025") | 57 | + msg = protocol.NewMessage("10025") |
58 | ctx.Output.JSON(msg, false, false) | 58 | ctx.Output.JSON(msg, false, false) |
59 | return | 59 | return |
60 | } | 60 | } |
@@ -64,14 +64,12 @@ var AuthToken = func(ctx *context.Context) { | @@ -64,14 +64,12 @@ var AuthToken = func(ctx *context.Context) { | ||
64 | return | 64 | return |
65 | } | 65 | } |
66 | if ok := serveauth.IsJwtErrorExpired(err); ok { | 66 | if ok := serveauth.IsJwtErrorExpired(err); ok { |
67 | - //token过期,刷新 | ||
68 | - logintoken, err := serveauth.RefreshLoginToken(refreshToken) | ||
69 | - msg = protocol.NewReturnResponse(logintoken, err) | 67 | + msg := protocol.NewMessage("10024") |
70 | ctx.Output.JSON(msg, false, false) | 68 | ctx.Output.JSON(msg, false, false) |
71 | return | 69 | return |
72 | } | 70 | } |
73 | - log.Error("token 校验失败") | ||
74 | - msg = protocol.NewMesage("1") | 71 | + log.Error("token 校验失败:%s", err) |
72 | + msg = protocol.NewMessage("10024") | ||
75 | ctx.Output.JSON(msg, false, false) | 73 | ctx.Output.JSON(msg, false, false) |
76 | return | 74 | return |
77 | } | 75 | } |
@@ -90,8 +88,8 @@ var AllowOption = func(ctx *context.Context) { | @@ -90,8 +88,8 @@ var AllowOption = func(ctx *context.Context) { | ||
90 | AllowAllOrigins: true, //允许的请求来源 | 88 | AllowAllOrigins: true, //允许的请求来源 |
91 | }) | 89 | }) |
92 | f(ctx) | 90 | f(ctx) |
93 | - ctx.Output.Body([]byte("{}")) | ||
94 | ctx.Output.SetStatus(204) | 91 | ctx.Output.SetStatus(204) |
92 | + ctx.Output.Body(nil) | ||
95 | return | 93 | return |
96 | } | 94 | } |
97 | 95 |
@@ -38,3 +38,14 @@ func GetMenuById(id int) (v *Menu, err error) { | @@ -38,3 +38,14 @@ func GetMenuById(id int) (v *Menu, err error) { | ||
38 | } | 38 | } |
39 | return nil, err | 39 | return nil, err |
40 | } | 40 | } |
41 | + | ||
42 | +func GetMenuByIds(ids []int64) (v []*Menu, err error) { | ||
43 | + o := orm.NewOrm() | ||
44 | + _, err = o.QueryTable(&Menu{}). | ||
45 | + Filter("id__in", ids). | ||
46 | + All(&v) | ||
47 | + if err == orm.ErrNoRows { | ||
48 | + return v, nil | ||
49 | + } | ||
50 | + return v, nil | ||
51 | +} |
@@ -7,8 +7,9 @@ import ( | @@ -7,8 +7,9 @@ import ( | ||
7 | type RoleMenu struct { | 7 | type RoleMenu struct { |
8 | Id int64 `orm:"column(id);auto" description:"主键"` | 8 | Id int64 `orm:"column(id);auto" description:"主键"` |
9 | RoleId int64 `orm:"column(role_id);null" description:"role.id"` | 9 | RoleId int64 `orm:"column(role_id);null" description:"role.id"` |
10 | - MenuId int64 `orm:"column(menu_id);null" description:"menu.id"` | 10 | + MenuId int `orm:"column(menu_id);null" description:"menu.id"` |
11 | Opption string `orm:"column(opption);size(500);null" description:"配置"` | 11 | Opption string `orm:"column(opption);size(500);null" description:"配置"` |
12 | + Code string `orm:"column(code)"` | ||
12 | } | 13 | } |
13 | 14 | ||
14 | func (t *RoleMenu) TableName() string { | 15 | func (t *RoleMenu) TableName() string { |
@@ -19,14 +20,6 @@ func init() { | @@ -19,14 +20,6 @@ func init() { | ||
19 | orm.RegisterModel(new(RoleMenu)) | 20 | orm.RegisterModel(new(RoleMenu)) |
20 | } | 21 | } |
21 | 22 | ||
22 | -// AddRoleMenu insert a new RoleMenu into database and returns | ||
23 | -// last inserted Id on success. | ||
24 | -func AddRoleMenu(m *RoleMenu) (id int64, err error) { | ||
25 | - o := orm.NewOrm() | ||
26 | - id, err = o.Insert(m) | ||
27 | - return | ||
28 | -} | ||
29 | - | ||
30 | func GetRoleMenuByRole(roleid int64) ([]RoleMenu, error) { | 23 | func GetRoleMenuByRole(roleid int64) ([]RoleMenu, error) { |
31 | var ( | 24 | var ( |
32 | list []RoleMenu | 25 | list []RoleMenu |
@@ -16,6 +16,7 @@ type User struct { | @@ -16,6 +16,7 @@ type User struct { | ||
16 | CsAccount int64 `orm:"column(cs_account)" description:"客服有话说ID"` | 16 | CsAccount int64 `orm:"column(cs_account)" description:"客服有话说ID"` |
17 | IsKefu int8 `orm:"column(is_kefu)" description:"是否是客服 0:否 1:是"` | 17 | IsKefu int8 `orm:"column(is_kefu)" description:"是否是客服 0:否 1:是"` |
18 | ImToken string `orm:"column(im_token);size(128)" description:"网易云token"` | 18 | ImToken string `orm:"column(im_token);size(128)" description:"网易云token"` |
19 | + Accid int64 `orm:"column(accid)" description:"网易云id"` | ||
19 | LastLoginTime time.Time `orm:"column(last_login_time);type(timestamp)" description:"最后一次登录时间"` | 20 | LastLoginTime time.Time `orm:"column(last_login_time);type(timestamp)" description:"最后一次登录时间"` |
20 | CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now_add" description:"创建时间"` | 21 | CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now_add" description:"创建时间"` |
21 | EnableStatus int8 `orm:"column(enable_status)" description:"是否有效"` | 22 | EnableStatus int8 `orm:"column(enable_status)" description:"是否有效"` |
@@ -133,7 +133,7 @@ type TemplateItem struct { | @@ -133,7 +133,7 @@ type TemplateItem struct { | ||
133 | 133 | ||
134 | type VisibleObject struct { | 134 | type VisibleObject struct { |
135 | Id string `json:"id"` | 135 | Id string `json:"id"` |
136 | - Name string `json:"name",omitempty` | 136 | + Name string `json:"name,omitempty"` |
137 | Type int `json:"type"` //1:部门 2:指定人员 | 137 | Type int `json:"type"` //1:部门 2:指定人员 |
138 | } | 138 | } |
139 | 139 |
@@ -2,7 +2,8 @@ package protocol | @@ -2,7 +2,8 @@ package protocol | ||
2 | 2 | ||
3 | //指定的请求头字段 | 3 | //指定的请求头字段 |
4 | const ( | 4 | const ( |
5 | - HeaderAccessToken string = "x-mmm-accesstoken" | 5 | + // HeaderAccessToken string = "x-mmm-accesstoken" |
6 | + HeaderAccessToken string = "Authorization" | ||
6 | HeaderRefreshToken string = "x-mmm-refreshtoken" | 7 | HeaderRefreshToken string = "x-mmm-refreshtoken" |
7 | ) | 8 | ) |
8 | 9 |
@@ -13,11 +13,15 @@ type ResponsePageInfo struct { | @@ -13,11 +13,15 @@ type ResponsePageInfo struct { | ||
13 | // ListData interface{} `json:"lists"` | 13 | // ListData interface{} `json:"lists"` |
14 | } | 14 | } |
15 | 15 | ||
16 | +type ResponseListData struct { | ||
17 | + List interface{} `json:"lists"` | ||
18 | +} | ||
19 | + | ||
16 | // DepartmentBase下拉选择列表-部门 | 20 | // DepartmentBase下拉选择列表-部门 |
17 | type DepartmentBase struct { | 21 | type DepartmentBase struct { |
18 | Id int64 `json:"id" orm:"column(id)"` | 22 | Id int64 `json:"id" orm:"column(id)"` |
19 | Name string `json:"name" orm:"column(name)"` | 23 | Name string `json:"name" orm:"column(name)"` |
20 | - ParentId int64 `json:"parent_id" orm:"column(parent_id)"` | 24 | + ParentId int64 `json:"parentId" orm:"column(parent_id)"` |
21 | } | 25 | } |
22 | 26 | ||
23 | //RoleBase 下拉选择列表-角色 | 27 | //RoleBase 下拉选择列表-角色 |
@@ -33,7 +37,7 @@ type RoleBase struct { | @@ -33,7 +37,7 @@ type RoleBase struct { | ||
33 | type PositionBase struct { | 37 | type PositionBase struct { |
34 | Id int64 `json:"id" orm:"column(id)"` | 38 | Id int64 `json:"id" orm:"column(id)"` |
35 | Name string `json:"name" orm:"column(name)"` | 39 | Name string `json:"name" orm:"column(name)"` |
36 | - ParentId int64 `json:"parent_id" orm:"column(parent_id)"` | 40 | + ParentId int64 `json:"parentId" orm:"column(parent_id)"` |
37 | } | 41 | } |
38 | 42 | ||
39 | //DepartUserBase 下拉选择列表-部门下的人员 | 43 | //DepartUserBase 下拉选择列表-部门下的人员 |
@@ -41,3 +45,9 @@ type DepartUserBase struct { | @@ -41,3 +45,9 @@ type DepartUserBase struct { | ||
41 | UserCompanyId int64 `json:"id" orm:"column(user_company_id)"` | 45 | UserCompanyId int64 `json:"id" orm:"column(user_company_id)"` |
42 | Name string `json:"name" orm:"-"` | 46 | Name string `json:"name" orm:"-"` |
43 | } | 47 | } |
48 | + | ||
49 | +//部门和人员混合 | ||
50 | +type DepartAndUser struct { | ||
51 | + Departments []DepartmentBase `json:"departments"` | ||
52 | + Members []DepartmentMember `json:"members"` | ||
53 | +} |
@@ -17,11 +17,6 @@ type DepartmentManager struct { | @@ -17,11 +17,6 @@ type DepartmentManager struct { | ||
17 | Name string `json:"name"` | 17 | Name string `json:"name"` |
18 | } | 18 | } |
19 | 19 | ||
20 | -type DepartmentMember struct { | ||
21 | - Id int64 `json:"id"` | ||
22 | - Name string `json:"name"` | ||
23 | -} | ||
24 | - | ||
25 | //RequestDepartmentEdit 编辑 | 20 | //RequestDepartmentEdit 编辑 |
26 | type RequestDepartmentEdit struct { | 21 | type RequestDepartmentEdit struct { |
27 | ID int64 `json:"id"` | 22 | ID int64 `json:"id"` |
@@ -35,12 +30,17 @@ type RequestDepartmentDelete struct { | @@ -35,12 +30,17 @@ type RequestDepartmentDelete struct { | ||
35 | CompanyID int64 `json:"company_id"` //公司 | 30 | CompanyID int64 `json:"company_id"` //公司 |
36 | } | 31 | } |
37 | 32 | ||
33 | +type DepartmentMember struct { | ||
34 | + Id int64 `json:"id"` | ||
35 | + Name string `json:"name"` | ||
36 | +} | ||
37 | + | ||
38 | //ResponseDepartmentInfo ... | 38 | //ResponseDepartmentInfo ... |
39 | type ResponseDepartmentInfo struct { | 39 | type ResponseDepartmentInfo struct { |
40 | ID int64 `json:"id"` | 40 | ID int64 `json:"id"` |
41 | CompanyID int64 `json:"company_id"` //公司 | 41 | CompanyID int64 `json:"company_id"` //公司 |
42 | Name string `json:"name"` //部门名字 | 42 | Name string `json:"name"` //部门名字 |
43 | - ParantID int64 `json:"parant_id"` //父级部门Id | 43 | + ParantID int64 `json:"parantId"` //父级部门Id |
44 | Manages []DepartmentManager `json:"manages"` //部门管理员 | 44 | Manages []DepartmentManager `json:"manages"` //部门管理员 |
45 | Members []DepartmentMember `json:"members"` //部门成员 | 45 | Members []DepartmentMember `json:"members"` //部门成员 |
46 | Member int64 `json:"member"` //成员数 | 46 | Member int64 `json:"member"` //成员数 |
@@ -32,7 +32,7 @@ type ResponseMessage struct { | @@ -32,7 +32,7 @@ type ResponseMessage struct { | ||
32 | Data interface{} `json:"data"` | 32 | Data interface{} `json:"data"` |
33 | } | 33 | } |
34 | 34 | ||
35 | -func NewMesage(code string) *ResponseMessage { | 35 | +func NewMessage(code string) *ResponseMessage { |
36 | ecode := SearchErr(code) | 36 | ecode := SearchErr(code) |
37 | rsp := &ResponseMessage{ | 37 | rsp := &ResponseMessage{ |
38 | Errno: transformCode(ecode.Errno), | 38 | Errno: transformCode(ecode.Errno), |
@@ -79,7 +79,7 @@ func (e ErrWithMessage) Unwrap() error { | @@ -79,7 +79,7 @@ func (e ErrWithMessage) Unwrap() error { | ||
79 | 79 | ||
80 | //ParseToMessage 实现CustomErrParse的接口 | 80 | //ParseToMessage 实现CustomErrParse的接口 |
81 | func (e ErrWithMessage) ParseToMessage() *ResponseMessage { | 81 | func (e ErrWithMessage) ParseToMessage() *ResponseMessage { |
82 | - return NewMesage(e.Errno) | 82 | + return NewMessage(e.Errno) |
83 | } | 83 | } |
84 | 84 | ||
85 | func SearchErr(code string) ErrorCode { | 85 | func SearchErr(code string) ErrorCode { |
@@ -90,7 +90,7 @@ func SearchErr(code string) ErrorCode { | @@ -90,7 +90,7 @@ func SearchErr(code string) ErrorCode { | ||
90 | func NewReturnResponse(data interface{}, eRR error) (msg *ResponseMessage) { | 90 | func NewReturnResponse(data interface{}, eRR error) (msg *ResponseMessage) { |
91 | // var msg *ResponseMessage | 91 | // var msg *ResponseMessage |
92 | if eRR == nil { | 92 | if eRR == nil { |
93 | - msg = NewMesage("0") | 93 | + msg = NewMessage("0") |
94 | msg.Data = data | 94 | msg.Data = data |
95 | return msg | 95 | return msg |
96 | } | 96 | } |
@@ -98,12 +98,12 @@ func NewReturnResponse(data interface{}, eRR error) (msg *ResponseMessage) { | @@ -98,12 +98,12 @@ func NewReturnResponse(data interface{}, eRR error) (msg *ResponseMessage) { | ||
98 | return x.ParseToMessage() | 98 | return x.ParseToMessage() |
99 | } | 99 | } |
100 | 100 | ||
101 | - return NewMesage("1") | 101 | + return NewMessage("1") |
102 | } | 102 | } |
103 | 103 | ||
104 | //BadRequestParam 控制层响应返回 | 104 | //BadRequestParam 控制层响应返回 |
105 | func BadRequestParam(code string) *ResponseMessage { | 105 | func BadRequestParam(code string) *ResponseMessage { |
106 | - return NewMesage(code) | 106 | + return NewMessage(code) |
107 | } | 107 | } |
108 | 108 | ||
109 | //NewPageDataResponse 控制层分页数据响应返回 | 109 | //NewPageDataResponse 控制层分页数据响应返回 |
@@ -112,9 +112,9 @@ func NewPageDataResponse(data interface{}, eRR error) (msg *ResponseMessage) { | @@ -112,9 +112,9 @@ func NewPageDataResponse(data interface{}, eRR error) (msg *ResponseMessage) { | ||
112 | if x, ok := eRR.(CustomErrParse); ok { | 112 | if x, ok := eRR.(CustomErrParse); ok { |
113 | return x.ParseToMessage() | 113 | return x.ParseToMessage() |
114 | } | 114 | } |
115 | - return NewMesage("1") | 115 | + return NewMessage("1") |
116 | } | 116 | } |
117 | - msg = NewMesage("0") | 117 | + msg = NewMessage("0") |
118 | msg.Data = map[string]interface{}{ | 118 | msg.Data = map[string]interface{}{ |
119 | "gridResult": data, | 119 | "gridResult": data, |
120 | } | 120 | } |
@@ -6,7 +6,7 @@ import ( | @@ -6,7 +6,7 @@ import ( | ||
6 | ) | 6 | ) |
7 | 7 | ||
8 | func Test_Err(t *testing.T) { | 8 | func Test_Err(t *testing.T) { |
9 | - errmsg := NewMesage("0") | 9 | + errmsg := NewMessage("0") |
10 | bt1, _ := json.Marshal(errmsg) | 10 | bt1, _ := json.Marshal(errmsg) |
11 | t.Log(string(bt1)) | 11 | t.Log(string(bt1)) |
12 | normalmsg := NewErrWithMessage("0") | 12 | normalmsg := NewErrWithMessage("0") |
@@ -7,6 +7,7 @@ var errmessge ErrorMap = map[string]string{ | @@ -7,6 +7,7 @@ var errmessge ErrorMap = map[string]string{ | ||
7 | //角色相关 | 7 | //角色相关 |
8 | "10001": "请先删除该分组下的其他角色", | 8 | "10001": "请先删除该分组下的其他角色", |
9 | "10002": "请先删除该角色下的人员", | 9 | "10002": "请先删除该角色下的人员", |
10 | + "10003": "无效角色", | ||
10 | //职位相关 | 11 | //职位相关 |
11 | "10011": "该职位已被使用无法删除", | 12 | "10011": "该职位已被使用无法删除", |
12 | //安全认证相关 | 13 | //安全认证相关 |
@@ -15,7 +16,7 @@ var errmessge ErrorMap = map[string]string{ | @@ -15,7 +16,7 @@ var errmessge ErrorMap = map[string]string{ | ||
15 | "10023": "用户无使用权限", | 16 | "10023": "用户无使用权限", |
16 | "10024": "登录凭证失效", | 17 | "10024": "登录凭证失效", |
17 | "10025": "该账号已在其他地方登录", | 18 | "10025": "该账号已在其他地方登录", |
18 | - "10026": "登录凭证过期", | 19 | + // "10026": "登录凭证过期", |
19 | "10027": "无操作权限", | 20 | "10027": "无操作权限", |
20 | //用户相关 | 21 | //用户相关 |
21 | "10031": "无效角色", | 22 | "10031": "无效角色", |
1 | package routers | 1 | package routers |
2 | 2 | ||
3 | +import ( | ||
4 | + "encoding/json" | ||
5 | +) | ||
6 | + | ||
3 | //PermissionBase 路由对应的权限 | 7 | //PermissionBase 路由对应的权限 |
4 | type PermissionBase struct { | 8 | type PermissionBase struct { |
5 | CodeName string //模块标识 | 9 | CodeName string //模块标识 |
6 | ActionName string | 10 | ActionName string |
7 | - MethodMap map[string]func() | ||
8 | -} | ||
9 | - | ||
10 | -func (p PermissionBase) ValidMapping(actionName string, fn func()) { | ||
11 | - p.MethodMap[actionName] = fn | 11 | + // MethodMap map[string]func() |
12 | } | 12 | } |
13 | 13 | ||
14 | var routerPermission = map[string]PermissionBase{ | 14 | var routerPermission = map[string]PermissionBase{ |
@@ -18,22 +18,61 @@ var routerPermission = map[string]PermissionBase{ | @@ -18,22 +18,61 @@ var routerPermission = map[string]PermissionBase{ | ||
18 | "/v1/department/delete": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "delete"}, | 18 | "/v1/department/delete": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "delete"}, |
19 | } | 19 | } |
20 | 20 | ||
21 | -//PermissionWithPosition 职位管理相关 | ||
22 | -// type PermissionWithPosition struct { | ||
23 | -// PermissionBase | ||
24 | -// } | 21 | +var permissionObject = map[string]interface{}{ |
22 | + "": 0, | ||
23 | +} | ||
24 | + | ||
25 | +//模块编号 | ||
26 | +const ( | ||
27 | + MENU_DEPARTMENT string = "OPPMG_DEPARTMENT" //公司部门管理模块 | ||
28 | + MENU_POSITION string = "OPPMG_POSITION" //公司职务管理 | ||
29 | + MENU_RBAC string = "OPPMG_RBAC" //员工角色/权限设置 | ||
30 | + MENU_USER string = "OPPMG_USER" //公司员工管理 | ||
31 | + MENU_ENTERPRISE_BASIC string = "OPPMG_ENTERPRISE_BASIC" //企业基础设置(大节点) | ||
32 | + MENU_SYSTEM_FUNCTION string = "OPPMG_SYSTEM_FUNCTION" //系统功能(大节点) | ||
33 | + MENU_CONMPANY string = "OPPMG_CONMPANY" //企业信息维护 | ||
34 | + MENU_CHANCE_TEMP string = "OPPMG_CHANCE_TEMP" //机会模板管理 | ||
35 | + MENU_SORCE string = "OPPMG_SORCE" //评分模式 | ||
36 | + MENU_CHANCE string = "OPPMG_CHANCE" //机会管理 | ||
37 | +) | ||
25 | 38 | ||
26 | -//GetCode 模块标识 | ||
27 | -// func (c *PermissionWithPosition) GetCodeName() string { | ||
28 | -// return "OPPMG_DEPARTMENT" | ||
29 | -// } | 39 | +type PermissionContentObject interface { |
40 | + StringUnmarshal(string) error | ||
41 | + ObjectMarshal() (string, error) | ||
42 | +} | ||
30 | 43 | ||
31 | -//Valid 权限校验 | ||
32 | -// func (c PermissionWithPosition) Valid(userCompanyID int64) bool { | ||
33 | -// return true | ||
34 | -// } | 44 | +type PermissionContentBase struct { |
45 | + Check int8 `json:"check"` | ||
46 | +} | ||
35 | 47 | ||
36 | -//PermissionWithDepart 部门管理相关 | ||
37 | -// type PermissionWithDepart struct { | ||
38 | -// Check int8 `json:"check"` | ||
39 | -// } | 48 | +func NewPermissionContentBase() PermissionContentObject { |
49 | + return &PermissionContentBase{} | ||
50 | +} | ||
51 | + | ||
52 | +func (p *PermissionContentBase) StringUnmarshal(s string) error { | ||
53 | + err := json.Unmarshal([]byte(s), p) | ||
54 | + return err | ||
55 | +} | ||
56 | + | ||
57 | +func (p *PermissionContentBase) ObjectMarshal() (string, error) { | ||
58 | + bt, err := json.Marshal(p) | ||
59 | + if err != nil { | ||
60 | + return "", err | ||
61 | + } | ||
62 | + return string(bt), err | ||
63 | +} | ||
64 | + | ||
65 | +type CodeToObject func() PermissionContentObject | ||
66 | + | ||
67 | +var CodePermissionObject = map[string]CodeToObject{ | ||
68 | + MENU_DEPARTMENT: NewPermissionContentBase, //公司部门管理模块 | ||
69 | + MENU_POSITION: NewPermissionContentBase, //公司职务管理 | ||
70 | + MENU_RBAC: NewPermissionContentBase, //员工角色/权限设置 | ||
71 | + MENU_USER: NewPermissionContentBase, //公司员工管理 | ||
72 | + MENU_ENTERPRISE_BASIC: NewPermissionContentBase, //企业基础设置(大节点) | ||
73 | + MENU_SYSTEM_FUNCTION: NewPermissionContentBase, //系统功能(大节点) | ||
74 | + MENU_CONMPANY: NewPermissionContentBase, //企业信息维护 | ||
75 | + MENU_CHANCE_TEMP: NewPermissionContentBase, //机会模板管理 | ||
76 | + MENU_SORCE: NewPermissionContentBase, //评分模式 | ||
77 | + MENU_CHANCE: NewPermissionContentBase, //机会管理 | ||
78 | +} |
@@ -3,6 +3,8 @@ package routers | @@ -3,6 +3,8 @@ package routers | ||
3 | import ( | 3 | import ( |
4 | "oppmg/controllers" | 4 | "oppmg/controllers" |
5 | 5 | ||
6 | + "github.com/astaxie/beego/context" | ||
7 | + | ||
6 | "oppmg/middleware" | 8 | "oppmg/middleware" |
7 | 9 | ||
8 | "github.com/astaxie/beego" | 10 | "github.com/astaxie/beego" |
@@ -36,6 +38,7 @@ func init() { | @@ -36,6 +38,7 @@ func init() { | ||
36 | beego.NSRouter("/role/list", &controllers.RbacController{}, "post:RoleList"), | 38 | beego.NSRouter("/role/list", &controllers.RbacController{}, "post:RoleList"), |
37 | beego.NSRouter("/menu/list", &controllers.RbacController{}, "post:MenuList"), | 39 | beego.NSRouter("/menu/list", &controllers.RbacController{}, "post:MenuList"), |
38 | beego.NSRouter("/role/menu", &controllers.RbacController{}, "post:RoleHasMenu"), | 40 | beego.NSRouter("/role/menu", &controllers.RbacController{}, "post:RoleHasMenu"), |
41 | + beego.NSRouter("/role/menu/edit", &controllers.RbacController{}, "post:RoleMenuEdit"), | ||
39 | ), | 42 | ), |
40 | beego.NSNamespace("/user", | 43 | beego.NSNamespace("/user", |
41 | beego.NSRouter("/list", &controllers.CompanyController{}, "post:UserList"), | 44 | beego.NSRouter("/list", &controllers.CompanyController{}, "post:UserList"), |
@@ -62,6 +65,7 @@ func init() { | @@ -62,6 +65,7 @@ func init() { | ||
62 | beego.NSRouter("/department", &controllers.CommonController{}, "post:SelectorDepartment"), | 65 | beego.NSRouter("/department", &controllers.CommonController{}, "post:SelectorDepartment"), |
63 | beego.NSRouter("/role", &controllers.CommonController{}, "post:SelectorRole"), | 66 | beego.NSRouter("/role", &controllers.CommonController{}, "post:SelectorRole"), |
64 | beego.NSRouter("/position", &controllers.CommonController{}, "post:SelectorPosition"), | 67 | beego.NSRouter("/position", &controllers.CommonController{}, "post:SelectorPosition"), |
68 | + beego.NSRouter("/user_and_department", &controllers.CommonController{}, "post:SelectorUserAndDepart"), | ||
65 | ), | 69 | ), |
66 | beego.NSNamespace("/template", | 70 | beego.NSNamespace("/template", |
67 | beego.NSRouter("/add", &controllers.TemplateController{}, "post:TemplateAdd"), | 71 | beego.NSRouter("/add", &controllers.TemplateController{}, "post:TemplateAdd"), |
@@ -88,9 +92,20 @@ func init() { | @@ -88,9 +92,20 @@ func init() { | ||
88 | beego.NSRouter("/company", &controllers.CompanyController{}, "post:InitCompany"), | 92 | beego.NSRouter("/company", &controllers.CompanyController{}, "post:InitCompany"), |
89 | beego.NSRouter("/company/info", &controllers.CompanyController{}, "post:GetCompanyForUCenter"), | 93 | beego.NSRouter("/company/info", &controllers.CompanyController{}, "post:GetCompanyForUCenter"), |
90 | ) | 94 | ) |
95 | + | ||
91 | beego.AddNamespace(nsV1) | 96 | beego.AddNamespace(nsV1) |
92 | beego.AddNamespace(nsAuth) | 97 | beego.AddNamespace(nsAuth) |
93 | beego.AddNamespace(nsUcenter) | 98 | beego.AddNamespace(nsUcenter) |
94 | 99 | ||
100 | + nsTest := beego.NewNamespace("/test", | ||
101 | + beego.NSCond(func(ctx *context.Context) bool { | ||
102 | + if beego.BConfig.RunMode != "prod" { | ||
103 | + return true | ||
104 | + } | ||
105 | + return false | ||
106 | + }), | ||
107 | + beego.NSRouter("/te", &controllers.RbacController{}, "get:GetRoleMenuAll"), | ||
108 | + ) | ||
109 | + beego.AddNamespace(nsTest) | ||
95 | beego.SetStaticPath("/log", beego.AppConfig.String("log_filename")) | 110 | beego.SetStaticPath("/log", beego.AppConfig.String("log_filename")) |
96 | } | 111 | } |
@@ -3,11 +3,13 @@ package auth | @@ -3,11 +3,13 @@ package auth | ||
3 | import ( | 3 | import ( |
4 | "crypto/sha1" | 4 | "crypto/sha1" |
5 | "encoding/hex" | 5 | "encoding/hex" |
6 | + "encoding/json" | ||
6 | "fmt" | 7 | "fmt" |
7 | "io" | 8 | "io" |
8 | "oppmg/common/log" | 9 | "oppmg/common/log" |
9 | "oppmg/models" | 10 | "oppmg/models" |
10 | "oppmg/protocol" | 11 | "oppmg/protocol" |
12 | + "oppmg/services/ucenter" | ||
11 | "oppmg/storage/redisdata" | 13 | "oppmg/storage/redisdata" |
12 | "oppmg/utils" | 14 | "oppmg/utils" |
13 | "strings" | 15 | "strings" |
@@ -79,7 +81,7 @@ func ResetLoginToken(loginToken protocol.LoginAuthToken) error { | @@ -79,7 +81,7 @@ func ResetLoginToken(loginToken protocol.LoginAuthToken) error { | ||
79 | uAuth.RefreshToken = loginToken.RefreshToken | 81 | uAuth.RefreshToken = loginToken.RefreshToken |
80 | uAuth.RefreshTokenExp = time.Unix(loginToken.RefreshExpires, 0) | 82 | uAuth.RefreshTokenExp = time.Unix(loginToken.RefreshExpires, 0) |
81 | uAuth.UpdateAt = nowTime | 83 | uAuth.UpdateAt = nowTime |
82 | - upCol := []string{"CurrentCompanyId", "AccessToken", "RefreshToken", "RefreshTokenExp", "UpdateAt"} | 84 | + upCol := []string{"CurrentCompanyId", "AccessTokenExp", "RefreshTokenExp", "AccessToken", "RefreshToken", "RefreshTokenExp", "UpdateAt"} |
83 | if err = models.UpdateUserAuthById(uAuth, upCol); err != nil { | 85 | if err = models.UpdateUserAuthById(uAuth, upCol); err != nil { |
84 | e := fmt.Errorf("UpdateUserAuthById err:%s", err) | 86 | e := fmt.Errorf("UpdateUserAuthById err:%s", err) |
85 | log.Error(e.Error()) | 87 | log.Error(e.Error()) |
@@ -189,7 +191,7 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro | @@ -189,7 +191,7 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro | ||
189 | } | 191 | } |
190 | if ok := userdata.IsEnable(); !ok { | 192 | if ok := userdata.IsEnable(); !ok { |
191 | log.Debug("userdata.IsEnable()==false") | 193 | log.Debug("userdata.IsEnable()==false") |
192 | - return logintoken, protocol.NewErrWithMessage("10021") | 194 | + return logintoken, protocol.NewErrWithMessage("10022") |
193 | } | 195 | } |
194 | if companys, err = getUserCompanyReal(userdata.Id); err != nil { | 196 | if companys, err = getUserCompanyReal(userdata.Id); err != nil { |
195 | log.Error("getUserCompanyReal err:%s", err) | 197 | log.Error("getUserCompanyReal err:%s", err) |
@@ -197,33 +199,55 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro | @@ -197,33 +199,55 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro | ||
197 | } | 199 | } |
198 | if len(companys) == 0 { | 200 | if len(companys) == 0 { |
199 | log.Debug("no company") | 201 | log.Debug("no company") |
200 | - return logintoken, protocol.NewErrWithMessage("10021") | 202 | + return logintoken, protocol.NewErrWithMessage("10022") |
201 | } | 203 | } |
202 | companyid = companys[0].Id | 204 | companyid = companys[0].Id |
203 | - // var uclientReturn ucenter.ResponseLogin | ||
204 | - // param := ucenter.RequesLogin{ | ||
205 | - // Phone: account, | ||
206 | - // Password: password, | ||
207 | - // } | ||
208 | - // uclient := ucenter.NewUCenterClient() | ||
209 | - // btBody, err := uclient.Call(param) | 205 | + // var uclientReturn *ucenter.ResponseLogin |
206 | + // uclientReturn, err = requestUCenterLogin(account, password) | ||
210 | // if err != nil { | 207 | // if err != nil { |
211 | - // log.Error("统一用户中心请求失败 err:%s", err) | ||
212 | - // return logintoken, protocol.NewErrWithMessage("1") | 208 | + // return logintoken, protocol.NewErrWithMessage("10021") |
213 | // } | 209 | // } |
214 | - // err = json.Unmarshal(btBody, &uclientReturn) | 210 | + // //更新用户数据 |
211 | + // _ = uclientReturn | ||
212 | + // userdata.Accid = uclientReturn.Data.Accid | ||
213 | + // userdata.Icon = uclientReturn.Data.Avatar | ||
214 | + // userdata.ImToken = uclientReturn.Data.Imtoken | ||
215 | + // userdata.NickName = uclientReturn.Data.NickName | ||
216 | + // userdata.CsAccount = uclientReturn.Data.CustomerAccount | ||
217 | + // userdata.LastLoginTime = time.Now() | ||
218 | + // err = models.UpdateUserById(userdata, []string{"Accid", "Icon", "ImToken", "NickName", "CsAccount", "LastLoginTime"}) | ||
215 | // if err != nil { | 219 | // if err != nil { |
216 | - // log.Error("解析统一用户中心响应失败 err:%s", err) | ||
217 | - // return logintoken, protocol.NewErrWithMessage("1") | ||
218 | - // } | ||
219 | - // if !(uclientReturn.Code == ucenter.ResponseCode0 && | ||
220 | - // uclientReturn.Msg == ucenter.ResponseMsgOk) { | ||
221 | - // return logintoken, protocol.NewErrWithMessage("10021") | 220 | + // log.Error("更新用户数据失败:%s", err) |
222 | // } | 221 | // } |
223 | logintoken, _ = GenerateAuthToken(userdata.Id, companyid) | 222 | logintoken, _ = GenerateAuthToken(userdata.Id, companyid) |
224 | return logintoken, err | 223 | return logintoken, err |
225 | } | 224 | } |
226 | 225 | ||
226 | +func requestUCenterLogin(account, password string) (*ucenter.ResponseLogin, error) { | ||
227 | + var uclientReturn *ucenter.ResponseLogin | ||
228 | + param := ucenter.RequesLogin{ | ||
229 | + Type: 1, | ||
230 | + Phone: account, | ||
231 | + Password: password, | ||
232 | + } | ||
233 | + uclient := ucenter.NewUCenterClient() | ||
234 | + btBody, err := uclient.Call(param) | ||
235 | + if err != nil { | ||
236 | + log.Error("统一用户中心请求失败 err:%s", err) | ||
237 | + return nil, protocol.NewErrWithMessage("1") | ||
238 | + } | ||
239 | + err = json.Unmarshal(btBody, &uclientReturn) | ||
240 | + if err != nil { | ||
241 | + log.Error("解析统一用户中心响应失败 err:%s", err) | ||
242 | + return nil, protocol.NewErrWithMessage("1") | ||
243 | + } | ||
244 | + if !(uclientReturn.Code == ucenter.ResponseCode0 && | ||
245 | + uclientReturn.Msg == ucenter.ResponseMsgOk) { | ||
246 | + return nil, protocol.NewErrWithMessage("10021") | ||
247 | + } | ||
248 | + return uclientReturn, nil | ||
249 | +} | ||
250 | + | ||
227 | type companybase struct { | 251 | type companybase struct { |
228 | Id int64 `orm:"column(id)"` | 252 | Id int64 `orm:"column(id)"` |
229 | Name string `orm:"coumn(name)"` | 253 | Name string `orm:"coumn(name)"` |
@@ -68,9 +68,9 @@ func GenerateAuthToken(uid int64, companyid int64) (protocol.LoginAuthToken, err | @@ -68,9 +68,9 @@ func GenerateAuthToken(uid int64, companyid int64) (protocol.LoginAuthToken, err | ||
68 | var ( | 68 | var ( |
69 | authToken protocol.LoginAuthToken | 69 | authToken protocol.LoginAuthToken |
70 | accesstoken string //主token,请求用 | 70 | accesstoken string //主token,请求用 |
71 | - expiresIn int64 = 60 * 30 //主token过期时间,30分钟 | 71 | + expiresIn int64 = 60 * 60 * 2 //主token过期时间,30分钟 |
72 | refreshtoken string //副token,刷新主token用 | 72 | refreshtoken string //副token,刷新主token用 |
73 | - refreshExpires int64 = 60 * 30 * 2 //副token 过期时间 ,60分钟 | 73 | + refreshExpires int64 = 60 * 60 * 2 //副token 过期时间 ,60分钟 |
74 | err error | 74 | err error |
75 | nowtime = time.Now() | 75 | nowtime = time.Now() |
76 | ) | 76 | ) |
@@ -8,13 +8,21 @@ import ( | @@ -8,13 +8,21 @@ import ( | ||
8 | "oppmg/utils" | 8 | "oppmg/utils" |
9 | ) | 9 | ) |
10 | 10 | ||
11 | -func SelectorDepartment(companyid int64) []protocol.DepartmentBase { | ||
12 | - const dataSql string = `SELECT id,name,parent_id FROM department WHERE company_id = ? AND delete_at = 0` | 11 | +func SelectorDepartment(companyid int64, departmentid int64) []protocol.DepartmentBase { |
12 | + | ||
13 | var ( | 13 | var ( |
14 | err error | 14 | err error |
15 | departs []protocol.DepartmentBase | 15 | departs []protocol.DepartmentBase |
16 | + cond []interface{} | ||
17 | + where string | ||
16 | ) | 18 | ) |
17 | - err = utils.ExecuteQueryAll(&departs, dataSql, companyid) | 19 | + dataSql := `SELECT id,name,parent_id FROM department WHERE company_id = ? AND delete_at = 0 ` |
20 | + cond = append(cond, companyid) | ||
21 | + if departmentid >= 0 { | ||
22 | + cond = append(cond, departmentid) | ||
23 | + where += ` And parent_id=? ` | ||
24 | + } | ||
25 | + err = utils.ExecuteQueryAll(&departs, dataSql+where, cond...) | ||
18 | if err != nil { | 26 | if err != nil { |
19 | e := fmt.Errorf("EXECUTE SQL err:%s", err) | 27 | e := fmt.Errorf("EXECUTE SQL err:%s", err) |
20 | log.Error(e.Error()) | 28 | log.Error(e.Error()) |
@@ -105,3 +113,43 @@ func SelectorPosition(companyid int64) []protocol.PositionBase { | @@ -105,3 +113,43 @@ func SelectorPosition(companyid int64) []protocol.PositionBase { | ||
105 | return positions | 113 | return positions |
106 | 114 | ||
107 | } | 115 | } |
116 | + | ||
117 | +func SelectorUserAndDepartment(departid int64, companyId int64) (*protocol.DepartAndUser, error) { | ||
118 | + var ( | ||
119 | + mDepart *models.Department | ||
120 | + departsUser protocol.DepartAndUser | ||
121 | + departbase []protocol.DepartmentBase | ||
122 | + departMember []protocol.DepartmentMember | ||
123 | + err error | ||
124 | + where string | ||
125 | + cond []interface{} | ||
126 | + ) | ||
127 | + if departid > 0 { | ||
128 | + mDepart, err = models.GetDepartmentById(departid) | ||
129 | + if err != nil { | ||
130 | + log.Error("GetDepartmentById err:%s", err) | ||
131 | + return nil, protocol.NewErrWithMessage("1") | ||
132 | + } | ||
133 | + if mDepart.CompanyId != companyId { | ||
134 | + log.Error("companyid err") | ||
135 | + return nil, protocol.NewErrWithMessage("1") | ||
136 | + } | ||
137 | + departMember = mDepart.GetMembers() | ||
138 | + departsUser.Members = departMember | ||
139 | + } | ||
140 | + datasql0 := `SELECT id, company_id,name,parent_id ` + | ||
141 | + ` FROM department WHERE company_id = ? AND delete_at = 0 ` | ||
142 | + cond = append(cond, companyId) | ||
143 | + if departid >= 0 { | ||
144 | + cond = append(cond, departid) | ||
145 | + where += ` AND parent_id =? ` | ||
146 | + } | ||
147 | + err = utils.ExecuteQueryAll(&departbase, datasql0+where, cond...) | ||
148 | + if err != nil { | ||
149 | + e := fmt.Errorf("EXECUTE SQL err:%s", err) | ||
150 | + log.Error(e.Error()) | ||
151 | + return nil, protocol.NewErrWithMessage("1", err) | ||
152 | + } | ||
153 | + departsUser.Departments = departbase | ||
154 | + return &departsUser, nil | ||
155 | +} |
@@ -380,7 +380,7 @@ func GetDepartmentUser(companyid int64, departmentid int64) ([]protocol.DepartUs | @@ -380,7 +380,7 @@ func GetDepartmentUser(companyid int64, departmentid int64) ([]protocol.DepartUs | ||
380 | department, err = models.GetDepartmentById(departmentid) | 380 | department, err = models.GetDepartmentById(departmentid) |
381 | if err != nil { | 381 | if err != nil { |
382 | log.Error("获取部门失败:%s", err) | 382 | log.Error("获取部门失败:%s", err) |
383 | - return nil, protocol.NewErrWithMessage("1") | 383 | + return nil, nil |
384 | } | 384 | } |
385 | if department.CompanyId != companyid { | 385 | if department.CompanyId != companyid { |
386 | log.Error("deparment.CompanyId err") | 386 | log.Error("deparment.CompanyId err") |
services/rbac/menu.go
0 → 100644
1 | +package rbac | ||
2 | + | ||
3 | +import ( | ||
4 | + "oppmg/common/log" | ||
5 | + "oppmg/models" | ||
6 | + "oppmg/protocol" | ||
7 | + "oppmg/utils" | ||
8 | + | ||
9 | + "github.com/astaxie/beego/orm" | ||
10 | +) | ||
11 | + | ||
12 | +//获取全部的权限菜单 | ||
13 | +func GetMenuAll() ([]protocol.PermissionItem, error) { | ||
14 | + const datasql string = `SELECT id,name,icon,parent_id,senior_status,sort,code | ||
15 | + FROM menu WHERE enabled=1 ORDER BY sort ` | ||
16 | + var ( | ||
17 | + list []protocol.PermissionItem | ||
18 | + err error | ||
19 | + ) | ||
20 | + err = utils.ExecuteQueryAll(&list, datasql) | ||
21 | + if err != nil { | ||
22 | + log.Error("EXECUTE SQL err:%s", err) | ||
23 | + return nil, protocol.NewErrWithMessage("1") | ||
24 | + } | ||
25 | + return list, nil | ||
26 | +} | ||
27 | + | ||
28 | +// | ||
29 | +func GetRoleHasMenu(roleid int64, companyid int64) (*protocol.ResponseRoleMenus, error) { | ||
30 | + var ( | ||
31 | + roleData *models.Role | ||
32 | + err error | ||
33 | + ) | ||
34 | + roleData, err = models.GetRoleById(roleid) | ||
35 | + if err != nil { | ||
36 | + log.Error("获取角色数据失败:%s", err) | ||
37 | + return nil, err | ||
38 | + } | ||
39 | + if roleData.Types != models.ROLETYPES_ROLE { | ||
40 | + log.Error("角色类型错误") | ||
41 | + return nil, protocol.NewErrWithMessage("1") | ||
42 | + } | ||
43 | + if roleData.CompanyId != companyid { | ||
44 | + log.Error("角色的公司id不匹配") | ||
45 | + return nil, protocol.NewErrWithMessage("1") | ||
46 | + } | ||
47 | + var ( | ||
48 | + rolemenu []models.RoleMenu | ||
49 | + ids []int64 | ||
50 | + ) | ||
51 | + rolemenu, err = models.GetRoleMenuByRole(roleid) | ||
52 | + if err != nil { | ||
53 | + log.Error("获取角色下的菜单数据失败:%s", err) | ||
54 | + return nil, protocol.NewErrWithMessage("1") | ||
55 | + } | ||
56 | + for _, v := range rolemenu { | ||
57 | + ids = append(ids, int64(v.MenuId)) | ||
58 | + } | ||
59 | + data := &protocol.ResponseRoleMenus{ | ||
60 | + RoleId: roleData.Id, | ||
61 | + RoleName: roleData.Name, | ||
62 | + MenuId: ids, | ||
63 | + } | ||
64 | + return data, nil | ||
65 | +} | ||
66 | + | ||
67 | +func GetRoleHasMenuAll(roleid int64, companyid int64) (map[string]PermissionContentObject, error) { | ||
68 | + var ( | ||
69 | + roleData *models.Role | ||
70 | + err error | ||
71 | + ) | ||
72 | + roleData, err = models.GetRoleById(roleid) | ||
73 | + if err != nil { | ||
74 | + log.Error("获取角色数据失败:%s", err) | ||
75 | + return nil, err | ||
76 | + } | ||
77 | + if roleData.Types != models.ROLETYPES_ROLE { | ||
78 | + log.Error("角色类型错误") | ||
79 | + return nil, protocol.NewErrWithMessage("1") | ||
80 | + } | ||
81 | + if roleData.CompanyId != companyid { | ||
82 | + log.Error("角色的公司id不匹配") | ||
83 | + return nil, protocol.NewErrWithMessage("1") | ||
84 | + } | ||
85 | + var ( | ||
86 | + rolemenu []models.RoleMenu | ||
87 | + returnList = make(map[string]PermissionContentObject) | ||
88 | + ) | ||
89 | + rolemenu, err = models.GetRoleMenuByRole(roleid) | ||
90 | + if err != nil { | ||
91 | + log.Error("获取角色下的菜单数据失败:%s", err) | ||
92 | + return nil, protocol.NewErrWithMessage("1") | ||
93 | + } | ||
94 | + for _, v := range rolemenu { | ||
95 | + if fn, ok := CodePermissionObject[v.Code]; ok { | ||
96 | + obj := fn() | ||
97 | + err := obj.StringUnmarshal(v.Opption) | ||
98 | + if err != nil { | ||
99 | + log.Error("解析权限规则失败", err) | ||
100 | + continue | ||
101 | + } | ||
102 | + returnList[v.Code] = obj | ||
103 | + } | ||
104 | + } | ||
105 | + return returnList, nil | ||
106 | +} | ||
107 | + | ||
108 | +func RoleMenuEdit(companyid int64, roleId int64, menuids []int64) error { | ||
109 | + roleMenus, err := GetRoleHasMenu(companyid, roleId) | ||
110 | + if err != nil { | ||
111 | + return err | ||
112 | + } | ||
113 | + var ( | ||
114 | + oldMenuIds []int64 | ||
115 | + addMenuIds []int64 | ||
116 | + delMenuIds []int64 | ||
117 | + addMenu []*models.Menu | ||
118 | + ) | ||
119 | + oldMenuIds = roleMenus.MenuId | ||
120 | + addMenuIds = utils.ArrayInt64Diff(menuids, oldMenuIds) | ||
121 | + delMenuIds = utils.ArrayInt64Diff(oldMenuIds, menuids) | ||
122 | + if len(addMenuIds) > 0 { | ||
123 | + addMenu, err = models.GetMenuByIds(addMenuIds) | ||
124 | + if err != nil { | ||
125 | + log.Error("获取菜单数据失败:%s", err) | ||
126 | + return protocol.NewErrWithMessage("1") | ||
127 | + } | ||
128 | + } | ||
129 | + o := orm.NewOrm() | ||
130 | + o.Begin() | ||
131 | + if len(delMenuIds) > 0 { | ||
132 | + _, err = o.QueryTable(&models.RoleMenu{}). | ||
133 | + Filter("role_id", roleId). | ||
134 | + Filter("menu_id__in", delMenuIds). | ||
135 | + Delete() | ||
136 | + if err != nil { | ||
137 | + log.Error("删除角色和菜单关系失败:%s", err) | ||
138 | + o.Rollback() | ||
139 | + return protocol.NewErrWithMessage("1") | ||
140 | + } | ||
141 | + } | ||
142 | + for _, v := range addMenu { | ||
143 | + m := models.RoleMenu{ | ||
144 | + RoleId: roleId, | ||
145 | + MenuId: v.Id, | ||
146 | + Code: v.Code, | ||
147 | + Opption: "{}", | ||
148 | + } | ||
149 | + if _, err = o.Insert(&m); err != nil { | ||
150 | + log.Error("添加角色和菜单关系失败:%s", err) | ||
151 | + o.Rollback() | ||
152 | + return protocol.NewErrWithMessage("1") | ||
153 | + } | ||
154 | + } | ||
155 | + o.Commit() | ||
156 | + return nil | ||
157 | + | ||
158 | +} |
1 | package rbac | 1 | package rbac |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | - "oppmg/common/log" | ||
5 | - "oppmg/models" | ||
6 | - "oppmg/protocol" | ||
7 | - "oppmg/utils" | 4 | + "encoding/json" |
8 | ) | 5 | ) |
9 | 6 | ||
10 | -//获取全部的权限菜单 | ||
11 | -func GetMenuAll() ([]protocol.PermissionItem, error) { | ||
12 | - const datasql string = `SELECT id,name,icon,parent_id,senior_status,sort,code | ||
13 | - FROM menu WHERE enabled=1 ORDER BY sort ` | ||
14 | - var ( | ||
15 | - list []protocol.PermissionItem | ||
16 | - err error | ||
17 | - ) | ||
18 | - err = utils.ExecuteQueryAll(&list, datasql) | ||
19 | - if err != nil { | ||
20 | - log.Error("EXECUTE SQL err:%s", err) | ||
21 | - return nil, protocol.NewErrWithMessage("1") | ||
22 | - } | ||
23 | - return list, nil | 7 | +//PermissionBase 路由对应的权限 |
8 | +type PermissionBase struct { | ||
9 | + CodeName string //模块标识 | ||
10 | + ActionName string | ||
11 | + // MethodMap map[string]func() | ||
24 | } | 12 | } |
25 | 13 | ||
26 | -// | ||
27 | -func GetRoleHasMenu(roleid int64, companyid int64) (*protocol.ResponseRoleMenus, error) { | ||
28 | - var ( | ||
29 | - roleData *models.Role | ||
30 | - err error | ||
31 | - ) | ||
32 | - roleData, err = models.GetRoleById(roleid) | ||
33 | - if err != nil { | ||
34 | - log.Error("获取角色数据失败:%s", err) | ||
35 | - return nil, err | ||
36 | - } | ||
37 | - if roleData.Types != models.ROLETYPES_ROLE { | ||
38 | - log.Error("角色类型错误") | ||
39 | - return nil, protocol.NewErrWithMessage("1") | ||
40 | - } | ||
41 | - if roleData.CompanyId != companyid { | ||
42 | - log.Error("角色的公司id不匹配") | ||
43 | - return nil, protocol.NewErrWithMessage("1") | ||
44 | - } | ||
45 | - var ( | ||
46 | - rolemenu []models.RoleMenu | ||
47 | - ids []int64 | ||
48 | - ) | ||
49 | - rolemenu, err = models.GetRoleMenuByRole(roleid) | 14 | +var routerPermission = map[string]PermissionBase{ |
15 | + "/v1/department/list": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "check"}, | ||
16 | + "/v1/department/add": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "add"}, | ||
17 | + "/v1/department/edit": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "edit"}, | ||
18 | + "/v1/department/delete": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "delete"}, | ||
19 | +} | ||
20 | + | ||
21 | +var permissionObject = map[string]interface{}{ | ||
22 | + "": 0, | ||
23 | +} | ||
24 | + | ||
25 | +//模块编号 | ||
26 | +const ( | ||
27 | + MENU_DEPARTMENT string = "OPPMG_DEPARTMENT" //公司部门管理模块 | ||
28 | + MENU_POSITION string = "OPPMG_POSITION" //公司职务管理 | ||
29 | + MENU_RBAC string = "OPPMG_RBAC" //员工角色/权限设置 | ||
30 | + MENU_USER string = "OPPMG_USER" //公司员工管理 | ||
31 | + MENU_ENTERPRISE_BASIC string = "OPPMG_ENTERPRISE_BASIC" //企业基础设置(大节点) | ||
32 | + MENU_SYSTEM_FUNCTION string = "OPPMG_SYSTEM_FUNCTION" //系统功能(大节点) | ||
33 | + MENU_CONMPANY string = "OPPMG_CONMPANY" //企业信息维护 | ||
34 | + MENU_CHANCE_TEMP string = "OPPMG_CHANCE_TEMP" //机会模板管理 | ||
35 | + MENU_SORCE string = "OPPMG_SORCE" //评分模式 | ||
36 | + MENU_CHANCE string = "OPPMG_CHANCE" //机会管理 | ||
37 | +) | ||
38 | + | ||
39 | +type PermissionContentObject interface { | ||
40 | + StringUnmarshal(string) error | ||
41 | + ObjectMarshal() (string, error) | ||
42 | +} | ||
43 | + | ||
44 | +type PermissionContentBase struct { | ||
45 | + Check int8 `json:"check"` | ||
46 | +} | ||
47 | + | ||
48 | +func NewPermissionContentBase() PermissionContentObject { | ||
49 | + return &PermissionContentBase{} | ||
50 | +} | ||
51 | + | ||
52 | +func (p *PermissionContentBase) StringUnmarshal(s string) error { | ||
53 | + err := json.Unmarshal([]byte(s), p) | ||
54 | + return err | ||
55 | +} | ||
56 | + | ||
57 | +func (p *PermissionContentBase) ObjectMarshal() (string, error) { | ||
58 | + bt, err := json.Marshal(p) | ||
50 | if err != nil { | 59 | if err != nil { |
51 | - log.Error("获取角色下的菜单数据失败:%s", err) | ||
52 | - return nil, protocol.NewErrWithMessage("1") | ||
53 | - } | ||
54 | - for _, v := range rolemenu { | ||
55 | - ids = append(ids, v.MenuId) | 60 | + return "", err |
56 | } | 61 | } |
57 | - data := &protocol.ResponseRoleMenus{ | ||
58 | - RoleId: roleData.Id, | ||
59 | - RoleName: roleData.Name, | ||
60 | - MenuId: ids, | ||
61 | - } | ||
62 | - return data, nil | 62 | + return string(bt), err |
63 | } | 63 | } |
64 | 64 | ||
65 | -func RoleMenuEdit(companyid int64, roleid int64, menuids []int64) { | ||
66 | 65 | ||
66 | +type CodeToObject func() PermissionContentObject | ||
67 | + | ||
68 | +var CodePermissionObject = map[string]CodeToObject{ | ||
69 | + MENU_DEPARTMENT: NewPermissionContentBase, //公司部门管理模块 | ||
70 | + MENU_POSITION: NewPermissionContentBase, //公司职务管理 | ||
71 | + MENU_RBAC: NewPermissionContentBase, //员工角色/权限设置 | ||
72 | + MENU_USER: NewPermissionContentBase, //公司员工管理 | ||
73 | + MENU_ENTERPRISE_BASIC: NewPermissionContentBase, //企业基础设置(大节点) | ||
74 | + MENU_SYSTEM_FUNCTION: NewPermissionContentBase, //系统功能(大节点) | ||
75 | + MENU_CONMPANY: NewPermissionContentBase, //企业信息维护 | ||
76 | + MENU_CHANCE_TEMP: NewPermissionContentBase, //机会模板管理 | ||
77 | + MENU_SORCE: NewPermissionContentBase, //评分模式 | ||
78 | + MENU_CHANCE: NewPermissionContentBase, //机会管理 | ||
67 | } | 79 | } |
@@ -158,11 +158,6 @@ func RoleGroupDelete(param protocol.RequestRoleDelete) error { | @@ -158,11 +158,6 @@ func RoleGroupDelete(param protocol.RequestRoleDelete) error { | ||
158 | return nil | 158 | return nil |
159 | } | 159 | } |
160 | 160 | ||
161 | -//CanSetRole 操作员是否可以操作角色 | ||
162 | -func CanSetRole(adminId int64, groupId int64) bool { | ||
163 | - return false | ||
164 | -} | ||
165 | - | ||
166 | func GetRoleList(companyId int64) ([]protocol.RoleGroup, error) { | 161 | func GetRoleList(companyId int64) ([]protocol.RoleGroup, error) { |
167 | var ( | 162 | var ( |
168 | roleGroups []protocol.RoleGroup | 163 | roleGroups []protocol.RoleGroup |
@@ -213,19 +208,3 @@ func getRoleGroupByCompany(companyid int64) ([]protocol.RoleInfo, error) { | @@ -213,19 +208,3 @@ func getRoleGroupByCompany(companyid int64) ([]protocol.RoleInfo, error) { | ||
213 | err = utils.ExecuteQueryAll(&roles, datasql, companyid, models.ROLETYPES_GROUP) | 208 | err = utils.ExecuteQueryAll(&roles, datasql, companyid, models.ROLETYPES_GROUP) |
214 | return roles, err | 209 | return roles, err |
215 | } | 210 | } |
216 | - | ||
217 | -func GetRoleGroup() error { | ||
218 | - return nil | ||
219 | -} | ||
220 | - | ||
221 | -func RoleHasPermission() error { | ||
222 | - return nil | ||
223 | -} | ||
224 | - | ||
225 | -func PermissionHasRole() error { | ||
226 | - return nil | ||
227 | -} | ||
228 | - | ||
229 | -func RolsHasUser() error { | ||
230 | - return nil | ||
231 | -} |
@@ -14,6 +14,7 @@ type CommResponse struct { | @@ -14,6 +14,7 @@ type CommResponse struct { | ||
14 | 14 | ||
15 | //RequesLogin 用户登录 | 15 | //RequesLogin 用户登录 |
16 | type RequesLogin struct { | 16 | type RequesLogin struct { |
17 | + Type int8 `json:"type"` | ||
17 | Password string `json:"password"` | 18 | Password string `json:"password"` |
18 | Phone string `json:"phone"` | 19 | Phone string `json:"phone"` |
19 | } | 20 | } |
@@ -27,7 +28,7 @@ func (r RequesLogin) Format() []byte { | @@ -27,7 +28,7 @@ func (r RequesLogin) Format() []byte { | ||
27 | 28 | ||
28 | //Format 实现IUCenterParam接口 | 29 | //Format 实现IUCenterParam接口 |
29 | func (r RequesLogin) GetPath() (string, string) { | 30 | func (r RequesLogin) GetPath() (string, string) { |
30 | - return "/auth/login", "POST" | 31 | + return "/auth/serverLogin", "POST" |
31 | } | 32 | } |
32 | 33 | ||
33 | //Format 实现IUCenterParam接口 | 34 | //Format 实现IUCenterParam接口 |
@@ -48,6 +49,9 @@ type ResponseLogin struct { | @@ -48,6 +49,9 @@ type ResponseLogin struct { | ||
48 | Phone string `json:"phone"` | 49 | Phone string `json:"phone"` |
49 | NickName string `json:"nickname"` //昵称 | 50 | NickName string `json:"nickname"` //昵称 |
50 | Avatar string `json:"avatar"` //头像 | 51 | Avatar string `json:"avatar"` //头像 |
52 | + Imtoken string `json:"imtoken"` //网易云imtoken | ||
53 | + Accid int64 `json:"accid"` | ||
54 | + CustomerAccount int64 `json:"customerAccount"` //客服id | ||
51 | } `json:"data"` | 55 | } `json:"data"` |
52 | } | 56 | } |
53 | 57 |
@@ -55,7 +55,7 @@ func buildCheckSum(nowTime string) string { | @@ -55,7 +55,7 @@ func buildCheckSum(nowTime string) string { | ||
55 | //httpDo post发送json | 55 | //httpDo post发送json |
56 | func (client UCenterClient) httpDo(path string, mathod string, posts []byte) ([]byte, error) { | 56 | func (client UCenterClient) httpDo(path string, mathod string, posts []byte) ([]byte, error) { |
57 | httpclient := http.Client{ | 57 | httpclient := http.Client{ |
58 | - Timeout: 5 * time.Second, //请求超时时间5秒 | 58 | + Timeout: 10 * time.Second, //请求超时时间5秒 |
59 | } | 59 | } |
60 | reqURL := client.baseUrl + path | 60 | reqURL := client.baseUrl + path |
61 | req, err := http.NewRequest(mathod, reqURL, bytes.NewReader(posts)) | 61 | req, err := http.NewRequest(mathod, reqURL, bytes.NewReader(posts)) |
@@ -64,7 +64,9 @@ func (client UCenterClient) httpDo(path string, mathod string, posts []byte) ([] | @@ -64,7 +64,9 @@ func (client UCenterClient) httpDo(path string, mathod string, posts []byte) ([] | ||
64 | } | 64 | } |
65 | req.Header = client.buildHeader() | 65 | req.Header = client.buildHeader() |
66 | resp, err := httpclient.Do(req) | 66 | resp, err := httpclient.Do(req) |
67 | + | ||
67 | log.Info("====>Send To UCenter:%s", string(posts)) | 68 | log.Info("====>Send To UCenter:%s", string(posts)) |
69 | + // log.Info("====>Send Header:%v", req.Header) | ||
68 | if err != nil { | 70 | if err != nil { |
69 | return nil, err | 71 | return nil, err |
70 | } | 72 | } |
@@ -9,5 +9,4 @@ type RedisLoginToken struct { | @@ -9,5 +9,4 @@ type RedisLoginToken struct { | ||
9 | AccessToken string `json:"access_token"` | 9 | AccessToken string `json:"access_token"` |
10 | RefreshToken string `json:"refresh_token"` | 10 | RefreshToken string `json:"refresh_token"` |
11 | CurrentCompany int64 `json:"current_company"` | 11 | CurrentCompany int64 `json:"current_company"` |
12 | - IsOk bool `json:"-"` | ||
13 | } | 12 | } |
@@ -23,7 +23,6 @@ func SetLoginToken(param protocol.LoginAuthToken, userid int64, companyid int64) | @@ -23,7 +23,6 @@ func SetLoginToken(param protocol.LoginAuthToken, userid int64, companyid int64) | ||
23 | AccessToken: param.AccessToken, | 23 | AccessToken: param.AccessToken, |
24 | RefreshToken: param.RefreshToken, | 24 | RefreshToken: param.RefreshToken, |
25 | CurrentCompany: companyid, | 25 | CurrentCompany: companyid, |
26 | - IsOk: true, | ||
27 | } | 26 | } |
28 | value, _ = json.Marshal(data) | 27 | value, _ = json.Marshal(data) |
29 | exp = param.RefreshExpires - nowTime | 28 | exp = param.RefreshExpires - nowTime |
@@ -67,8 +66,26 @@ func ExistLoginToken(userid int64) bool { | @@ -67,8 +66,26 @@ func ExistLoginToken(userid int64) bool { | ||
67 | func DeleteLoginToken(userid int64) error { | 66 | func DeleteLoginToken(userid int64) error { |
68 | client := redis.GetRedis() | 67 | client := redis.GetRedis() |
69 | key := fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_TOKEN, userid) | 68 | key := fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_TOKEN, userid) |
70 | - err:=client.Del(key).Err() | 69 | + err := client.Del(key).Err() |
71 | return err | 70 | return err |
72 | } | 71 | } |
73 | 72 | ||
73 | +// 刷新token 的有效期 | ||
74 | +func RefreshLoginTokenExpires(userid int64) error { | ||
75 | + client := redis.GetRedis() | ||
76 | + key := fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_TOKEN, userid) | ||
77 | + result, err := client.Exists(key).Result() | ||
78 | + if err != nil { | ||
79 | + return err | ||
80 | + } | ||
81 | + if result == 0 { | ||
82 | + return nil | ||
83 | + } | ||
84 | + _, err = client.Expire(key, 30*time.Minute).Result() | ||
85 | + if err != nil { | ||
86 | + return err | ||
87 | + } | ||
88 | + return nil | ||
89 | +} | ||
90 | + | ||
74 | //消息发布订阅 | 91 | //消息发布订阅 |
@@ -14,7 +14,7 @@ func ArrayInt64Diff(arr1 []int64, arr2 []int64) []int64 { | @@ -14,7 +14,7 @@ func ArrayInt64Diff(arr1 []int64, arr2 []int64) []int64 { | ||
14 | } | 14 | } |
15 | setmap := make(map[int64]bool) | 15 | setmap := make(map[int64]bool) |
16 | for i := range arr2 { | 16 | for i := range arr2 { |
17 | - setmap[arr1[i]] = true | 17 | + setmap[arr2[i]] = true |
18 | } | 18 | } |
19 | var result []int64 | 19 | var result []int64 |
20 | for i := range arr1 { | 20 | for i := range arr1 { |
@@ -26,6 +26,25 @@ func ArrayInt64Diff(arr1 []int64, arr2 []int64) []int64 { | @@ -26,6 +26,25 @@ func ArrayInt64Diff(arr1 []int64, arr2 []int64) []int64 { | ||
26 | return result | 26 | return result |
27 | } | 27 | } |
28 | 28 | ||
29 | +//ArrayIntDiff 返回切片的差集:arr1-arr2 | ||
30 | +func ArrayIntDiff(arr1 []int, arr2 []int) []int { | ||
31 | + if len(arr2) == 0 { | ||
32 | + return arr1 | ||
33 | + } | ||
34 | + setmap := make(map[int]bool) | ||
35 | + for i := range arr2 { | ||
36 | + setmap[arr1[i]] = true | ||
37 | + } | ||
38 | + var result []int | ||
39 | + for i := range arr1 { | ||
40 | + if _, ok := setmap[arr1[i]]; !ok { | ||
41 | + result = append(result, arr1[i]) | ||
42 | + } | ||
43 | + } | ||
44 | + | ||
45 | + return result | ||
46 | +} | ||
47 | + | ||
29 | //ArrayStringIn 检查s字符串是否在切片sl中 | 48 | //ArrayStringIn 检查s字符串是否在切片sl中 |
30 | func ArrayStringIn(arr1 []string, s string) bool { | 49 | func ArrayStringIn(arr1 []string, s string) bool { |
31 | for _, v := range arr1 { | 50 | for _, v := range arr1 { |
@@ -70,6 +70,7 @@ token 的响应内容 | @@ -70,6 +70,7 @@ token 的响应内容 | ||
70 | 70 | ||
71 | ```json | 71 | ```json |
72 | { | 72 | { |
73 | + "token":"" | ||
73 | "code": 0, | 74 | "code": 0, |
74 | "msg": "成功", | 75 | "msg": "成功", |
75 | "data": { | 76 | "data": { |
@@ -147,7 +148,6 @@ token 的响应内容 | @@ -147,7 +148,6 @@ token 的响应内容 | ||
147 | 148 | ||
148 | ## 公司部门管理 | 149 | ## 公司部门管理 |
149 | 150 | ||
150 | - | ||
151 | ### 部门列表 | 151 | ### 部门列表 |
152 | 152 | ||
153 | - 请求路径:/v1/department/list | 153 | - 请求路径:/v1/department/list |
@@ -155,9 +155,7 @@ token 的响应内容 | @@ -155,9 +155,7 @@ token 的响应内容 | ||
155 | - 请求 json: | 155 | - 请求 json: |
156 | 156 | ||
157 | ```json | 157 | ```json |
158 | -{ | ||
159 | - | ||
160 | -} | 158 | +{} |
161 | ``` | 159 | ``` |
162 | 160 | ||
163 | - 正常响应 json | 161 | - 正常响应 json |
@@ -167,16 +165,18 @@ token 的响应内容 | @@ -167,16 +165,18 @@ token 的响应内容 | ||
167 | "code": 0, | 165 | "code": 0, |
168 | "msg": "成功", | 166 | "msg": "成功", |
169 | "data": { | 167 | "data": { |
170 | - "list": [ | 168 | + "lists": [ |
171 | { | 169 | { |
172 | "id": 1, | 170 | "id": 1, |
173 | "company_id": 1, | 171 | "company_id": 1, |
174 | "name": "部门1", | 172 | "name": "部门1", |
175 | "parant_id": 0, | 173 | "parant_id": 0, |
176 | - "manages": [{ | ||
177 | - "id":1, | ||
178 | - "name":"主管" | ||
179 | - }], | 174 | + "manages": [ |
175 | + { | ||
176 | + "id": 1, | ||
177 | + "name": "主管" | ||
178 | + } | ||
179 | + ], | ||
180 | "member": 1 | 180 | "member": 1 |
181 | }, | 181 | }, |
182 | { | 182 | { |
@@ -184,10 +184,12 @@ token 的响应内容 | @@ -184,10 +184,12 @@ token 的响应内容 | ||
184 | "company_id": 1, | 184 | "company_id": 1, |
185 | "name": "部门1-2", | 185 | "name": "部门1-2", |
186 | "parant_id": 1, | 186 | "parant_id": 1, |
187 | - "manages": [{ | ||
188 | - "id":1, | ||
189 | - "name":"主管" | ||
190 | - }], | 187 | + "manages": [ |
188 | + { | ||
189 | + "id": 1, | ||
190 | + "name": "主管" | ||
191 | + } | ||
192 | + ], | ||
191 | "member": 1 | 193 | "member": 1 |
192 | } | 194 | } |
193 | ] | 195 | ] |
@@ -199,9 +201,6 @@ token 的响应内容 | @@ -199,9 +201,6 @@ token 的响应内容 | ||
199 | 201 | ||
200 | --- | 202 | --- |
201 | 203 | ||
202 | - | ||
203 | - | ||
204 | - | ||
205 | ### 添加部门 | 204 | ### 添加部门 |
206 | 205 | ||
207 | - 请求路径:/v1/department/add | 206 | - 请求路径:/v1/department/add |
@@ -289,7 +288,6 @@ token 的响应内容 | @@ -289,7 +288,6 @@ token 的响应内容 | ||
289 | 288 | ||
290 | ## 公司职位管理 | 289 | ## 公司职位管理 |
291 | 290 | ||
292 | - | ||
293 | ### 职位列表 | 291 | ### 职位列表 |
294 | 292 | ||
295 | - 请求路径:/v1/position/list | 293 | - 请求路径:/v1/position/list |
@@ -297,9 +295,7 @@ token 的响应内容 | @@ -297,9 +295,7 @@ token 的响应内容 | ||
297 | - 请求 json: | 295 | - 请求 json: |
298 | 296 | ||
299 | ```json | 297 | ```json |
300 | -{ | ||
301 | - | ||
302 | -} | 298 | +{} |
303 | ``` | 299 | ``` |
304 | 300 | ||
305 | - 响应 json | 301 | - 响应 json |
@@ -448,6 +444,7 @@ token 的响应内容 | @@ -448,6 +444,7 @@ token 的响应内容 | ||
448 | --- | 444 | --- |
449 | 445 | ||
450 | ## 公司员工角色 | 446 | ## 公司员工角色 |
447 | + | ||
451 | ### 角色列表 | 448 | ### 角色列表 |
452 | 449 | ||
453 | - 请求路径:/v1/rbac/role/list | 450 | - 请求路径:/v1/rbac/role/list |
@@ -455,15 +452,12 @@ token 的响应内容 | @@ -455,15 +452,12 @@ token 的响应内容 | ||
455 | - 请求 json: | 452 | - 请求 json: |
456 | 453 | ||
457 | ```json | 454 | ```json |
458 | -{ | ||
459 | - | ||
460 | -} | 455 | +{} |
461 | ``` | 456 | ``` |
462 | 457 | ||
463 | - 响应 json | 458 | - 响应 json |
464 | 459 | ||
465 | ```json | 460 | ```json |
466 | - | ||
467 | { | 461 | { |
468 | "code": 0, | 462 | "code": 0, |
469 | "msg": "成功", | 463 | "msg": "成功", |
@@ -569,9 +563,6 @@ token 的响应内容 | @@ -569,9 +563,6 @@ token 的响应内容 | ||
569 | 563 | ||
570 | --- | 564 | --- |
571 | 565 | ||
572 | - | ||
573 | - | ||
574 | - | ||
575 | ### 添加角色 | 566 | ### 添加角色 |
576 | 567 | ||
577 | - 请求路径:/v1/rbac/role/add | 568 | - 请求路径:/v1/rbac/role/add |
-
请 注册 或 登录 后发表评论