正在显示
6 个修改的文件
包含
122 行增加
和
14 行删除
| 1 | package controllers | 1 | package controllers |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "encoding/json" | ||
| 5 | + "fmt" | ||
| 4 | "oppmg/protocol" | 6 | "oppmg/protocol" |
| 7 | + serverbac "oppmg/services/rbac" | ||
| 5 | ) | 8 | ) |
| 6 | 9 | ||
| 7 | type AuditController struct { | 10 | type AuditController struct { |
| @@ -10,10 +13,10 @@ type AuditController struct { | @@ -10,10 +13,10 @@ type AuditController struct { | ||
| 10 | 13 | ||
| 11 | //AuditList 机会管理列表 | 14 | //AuditList 机会管理列表 |
| 12 | //@router /v1/audit/list [post] | 15 | //@router /v1/audit/list [post] |
| 13 | -func (this *AuditController) AuditList() { | 16 | +func (c *AuditController) AuditList() { |
| 14 | var msg *protocol.ResponseMessage | 17 | var msg *protocol.ResponseMessage |
| 15 | defer func() { | 18 | defer func() { |
| 16 | - this.ResposeJson(msg) | 19 | + c.ResposeJson(msg) |
| 17 | }() | 20 | }() |
| 18 | // var request *protocol.ConfigScoreRequest | 21 | // var request *protocol.ConfigScoreRequest |
| 19 | // if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil { | 22 | // if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil { |
| @@ -26,3 +29,9 @@ func (this *AuditController) AuditList() { | @@ -26,3 +29,9 @@ func (this *AuditController) AuditList() { | ||
| 26 | msg = protocol.NewReturnResponse(nil, nil) | 29 | msg = protocol.NewReturnResponse(nil, nil) |
| 27 | return | 30 | return |
| 28 | } | 31 | } |
| 32 | + | ||
| 33 | +func (c *AuditController) Test() { | ||
| 34 | + data, _ := serverbac.GetUserPermission(1) | ||
| 35 | + bt, _ := json.Marshal(data) | ||
| 36 | + fmt.Println(string(bt)) | ||
| 37 | +} |
| @@ -23,7 +23,7 @@ var LogRequestData = func(ctx *context.Context) { | @@ -23,7 +23,7 @@ var LogRequestData = func(ctx *context.Context) { | ||
| 23 | //protocol.HeaderRefreshToken: ctx.Input.Header(protocol.HeaderRefreshToken), | 23 | //protocol.HeaderRefreshToken: ctx.Input.Header(protocol.HeaderRefreshToken), |
| 24 | } | 24 | } |
| 25 | if ctx.Input.RequestBody != nil { | 25 | if ctx.Input.RequestBody != nil { |
| 26 | - log.Info("====>Recv data from client:\nHeadData: %v \nBodyData: %s", hmap, string(ctx.Input.RequestBody)) | 26 | + log.Info("====>Recv data from client:\nHeadData: %v \nBodyData: %s", hmap, string(ctx.Input.RequestBody[0:2000])) |
| 27 | } else { | 27 | } else { |
| 28 | log.Info("====>Recv data from client:\nHeadData: %v ", hmap) | 28 | log.Info("====>Recv data from client:\nHeadData: %v ", hmap) |
| 29 | } | 29 | } |
| @@ -129,4 +129,5 @@ func init() { | @@ -129,4 +129,5 @@ func init() { | ||
| 129 | beego.SetStaticPath("/log", beego.AppConfig.String("log_filename")) | 129 | beego.SetStaticPath("/log", beego.AppConfig.String("log_filename")) |
| 130 | beego.SetStaticPath("/file/opp", beego.AppConfig.String("file_save_path")) | 130 | beego.SetStaticPath("/file/opp", beego.AppConfig.String("file_save_path")) |
| 131 | beego.SetStaticPath("/static", "./static") | 131 | beego.SetStaticPath("/static", "./static") |
| 132 | + beego.NSRouter("/test", &controllers.AuditController{}, "get:Test") | ||
| 132 | } | 133 | } |
| 1 | package rbac | 1 | package rbac |
| 2 | 2 | ||
| 3 | +import ( | ||
| 4 | + "encoding/json" | ||
| 5 | + "fmt" | ||
| 6 | + "oppmg/common/log" | ||
| 7 | + "oppmg/utils" | ||
| 8 | +) | ||
| 9 | + | ||
| 3 | //模块编号 | 10 | //模块编号 |
| 4 | const ( | 11 | const ( |
| 5 | M_ENTERPRISE string = "ENTERPRISE" //企业基础设置 | 12 | M_ENTERPRISE string = "ENTERPRISE" //企业基础设置 |
| @@ -44,3 +51,40 @@ var CodePermissionObject = map[string]CodeToObject{ | @@ -44,3 +51,40 @@ var CodePermissionObject = map[string]CodeToObject{ | ||
| 44 | M_SYSTEM_RATING: NewPermissionOptionBase, //评分模式 | 51 | M_SYSTEM_RATING: NewPermissionOptionBase, //评分模式 |
| 45 | M_SYSTEM_OPPORTUNITY: NewPermissionOptionBase, //机会管理 | 52 | M_SYSTEM_OPPORTUNITY: NewPermissionOptionBase, //机会管理 |
| 46 | } | 53 | } |
| 54 | + | ||
| 55 | +func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, error) { | ||
| 56 | + type CodeOpptionData struct { | ||
| 57 | + Code string `orm:"column(code)"` | ||
| 58 | + Opption string `orm:"column(opption)"` | ||
| 59 | + } | ||
| 60 | + const datasql string = `SELECT a.code,a.opption | ||
| 61 | + FROM role_menu AS a | ||
| 62 | + JOIN user_role AS b ON a.role_id = b.role_id | ||
| 63 | + JOIN role AS c ON a.role_id = c.id | ||
| 64 | + WHERE b.user_company_id=31 AND c.delete_at =0` | ||
| 65 | + var ( | ||
| 66 | + data []CodeOpptionData | ||
| 67 | + err error | ||
| 68 | + objMap = make(map[string]PermissionOptionObject) | ||
| 69 | + ) | ||
| 70 | + err = utils.ExecuteQueryAll(&data, datasql, userCompanyid) | ||
| 71 | + if err != nil { | ||
| 72 | + e := fmt.Errorf("EXCUTE SQL ERR:%s", err) | ||
| 73 | + return nil, e | ||
| 74 | + } | ||
| 75 | + for _, v := range data { | ||
| 76 | + if _, ok := objMap[v.Code]; ok { | ||
| 77 | + err = objMap[v.Code].MergeObject(v.Opption) | ||
| 78 | + if err != nil { | ||
| 79 | + log.Warn(err.Error()) | ||
| 80 | + } | ||
| 81 | + continue | ||
| 82 | + } | ||
| 83 | + obj := CodePermissionObject[v.Code]() | ||
| 84 | + if err = json.Unmarshal([]byte(v.Opption), obj); err != nil { | ||
| 85 | + log.Debug("解析权限配置option 失败%s", err) | ||
| 86 | + } | ||
| 87 | + objMap[v.Code] = obj | ||
| 88 | + } | ||
| 89 | + return objMap, nil | ||
| 90 | +} |
| @@ -42,12 +42,14 @@ func (p *PermissionOptionBase) GetValidFunc(k string) func(UserObject) bool { | @@ -42,12 +42,14 @@ func (p *PermissionOptionBase) GetValidFunc(k string) func(UserObject) bool { | ||
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | func (p *PermissionOptionBase) MergeObject(jsonString string) error { | 44 | func (p *PermissionOptionBase) MergeObject(jsonString string) error { |
| 45 | - var obj PermissionBase | 45 | + var obj PermissionOptionBase |
| 46 | err := json.Unmarshal([]byte(jsonString), &obj) | 46 | err := json.Unmarshal([]byte(jsonString), &obj) |
| 47 | if err != nil { | 47 | if err != nil { |
| 48 | return err | 48 | return err |
| 49 | } | 49 | } |
| 50 | - // if o | 50 | + if obj.Check > p.Check { |
| 51 | + p.Check = obj.Check | ||
| 52 | + } | ||
| 51 | return nil | 53 | return nil |
| 52 | } | 54 | } |
| 53 | 55 | ||
| @@ -89,11 +91,13 @@ type CheckOpp struct { | @@ -89,11 +91,13 @@ type CheckOpp struct { | ||
| 89 | 91 | ||
| 90 | //OptionOpportunity 机会管理 高级权限设置 | 92 | //OptionOpportunity 机会管理 高级权限设置 |
| 91 | type OptionOpportunity struct { | 93 | type OptionOpportunity struct { |
| 92 | - Check int `json:"check"` | ||
| 93 | - CheckOption CheckOpp `json:"check_option"` | ||
| 94 | - EditSorce int `json:"edit_sorce"` | ||
| 95 | - EditPublicStatus int `json:"edit_public_status"` | ||
| 96 | - CloseChance int `json:"close_chance"` | 94 | + Check int `json:"check"` |
| 95 | + CheckMap map[int]int `json:"-"` | ||
| 96 | + CheckOption CheckOpp `json:"check_option"` | ||
| 97 | + EditSorce int `json:"edit_sorce"` | ||
| 98 | + EditPublicStatus int `json:"edit_public_status"` | ||
| 99 | + CloseChance int `json:"close_chance"` | ||
| 100 | + EditChance int `json:"edit_chance"` | ||
| 97 | } | 101 | } |
| 98 | 102 | ||
| 99 | /* | 103 | /* |
| @@ -116,6 +120,7 @@ var ( | @@ -116,6 +120,7 @@ var ( | ||
| 116 | 120 | ||
| 117 | func NewOptionOpportunity() PermissionOptionObject { | 121 | func NewOptionOpportunity() PermissionOptionObject { |
| 118 | return &OptionOpportunity{ | 122 | return &OptionOpportunity{ |
| 123 | + CheckMap: make(map[int]int), | ||
| 119 | CheckOption: CheckOpp{ | 124 | CheckOption: CheckOpp{ |
| 120 | Departments: []CheckDeparment{}, | 125 | Departments: []CheckDeparment{}, |
| 121 | }, | 126 | }, |
| @@ -134,7 +139,56 @@ func (p *OptionOpportunity) GetValidFunc(k string) func(UserObject) bool { | @@ -134,7 +139,56 @@ func (p *OptionOpportunity) GetValidFunc(k string) func(UserObject) bool { | ||
| 134 | } | 139 | } |
| 135 | 140 | ||
| 136 | //MergeObject PermissionOptionBase 接口实现 | 141 | //MergeObject PermissionOptionBase 接口实现 |
| 137 | -func (p *OptionOpportunity) MergeObject(string) error { | 142 | +func (p *OptionOpportunity) MergeObject(jsonString string) error { |
| 143 | + var obj OptionOpportunity | ||
| 144 | + err := json.Unmarshal([]byte(jsonString), &obj) | ||
| 145 | + if err != nil { | ||
| 146 | + return err | ||
| 147 | + } | ||
| 148 | + if p.CheckMap == nil { | ||
| 149 | + p.CheckMap = make(map[int]int) | ||
| 150 | + } | ||
| 151 | + p.CheckMap[obj.Check] = 1 | ||
| 152 | + departMap := make(map[int64]*CheckDeparment) | ||
| 153 | + for k := range p.CheckOption.Departments { | ||
| 154 | + i := p.CheckOption.Departments[k].Id | ||
| 155 | + departMap[i] = &p.CheckOption.Departments[k] | ||
| 156 | + } | ||
| 157 | + //列表合并 | ||
| 158 | + for k := range obj.CheckOption.Departments { | ||
| 159 | + i := obj.CheckOption.Departments[k].Id | ||
| 160 | + if _, ok := departMap[i]; ok { | ||
| 161 | + if obj.CheckOption.Departments[k].OpenAll > departMap[i].OpenAll { | ||
| 162 | + departMap[i].OpenAll = obj.CheckOption.Departments[k].OpenAll | ||
| 163 | + } | ||
| 164 | + if obj.CheckOption.Departments[k].OpenDepart > departMap[i].OpenDepart { | ||
| 165 | + departMap[i].OpenDepart = obj.CheckOption.Departments[k].OpenDepart | ||
| 166 | + } | ||
| 167 | + if obj.CheckOption.Departments[k].Wait > departMap[i].Wait { | ||
| 168 | + departMap[i].Wait = obj.CheckOption.Departments[k].Wait | ||
| 169 | + } | ||
| 170 | + } else { | ||
| 171 | + | ||
| 172 | + departMap[i] = &obj.CheckOption.Departments[k] | ||
| 173 | + | ||
| 174 | + } | ||
| 175 | + } | ||
| 176 | + p.CheckOption.Departments = make([]CheckDeparment, 0) | ||
| 177 | + for k := range departMap { | ||
| 178 | + p.CheckOption.Departments = append(p.CheckOption.Departments, *departMap[k]) | ||
| 179 | + } | ||
| 180 | + if obj.CloseChance > p.CloseChance { | ||
| 181 | + p.CloseChance = obj.CloseChance | ||
| 182 | + } | ||
| 183 | + if obj.EditPublicStatus > p.EditPublicStatus { | ||
| 184 | + p.EditPublicStatus = obj.EditPublicStatus | ||
| 185 | + } | ||
| 186 | + if obj.EditSorce > p.EditSorce { | ||
| 187 | + p.EditSorce = obj.EditSorce | ||
| 188 | + } | ||
| 189 | + if obj.EditChance > p.EditChance { | ||
| 190 | + p.EditChance = obj.EditChance | ||
| 191 | + } | ||
| 138 | return nil | 192 | return nil |
| 139 | } | 193 | } |
| 140 | 194 |
| @@ -125,8 +125,8 @@ func RequestUCenterSmsCodeCheck(phone string, captcha string) (*ResponseSmsCodeC | @@ -125,8 +125,8 @@ func RequestUCenterSmsCodeCheck(phone string, captcha string) (*ResponseSmsCodeC | ||
| 125 | log.Error("统一用户中心请求失败 err:%s", err) | 125 | log.Error("统一用户中心请求失败 err:%s", err) |
| 126 | return nil, protocol.NewErrWithMessage("1") | 126 | return nil, protocol.NewErrWithMessage("1") |
| 127 | } | 127 | } |
| 128 | - var ucenterReturn *ResponseSmsCodeCheck | ||
| 129 | - err = json.Unmarshal(btBody, ucenterReturn) | 128 | + var ucenterReturn ResponseSmsCodeCheck |
| 129 | + err = json.Unmarshal(btBody, &ucenterReturn) | ||
| 130 | if err != nil { | 130 | if err != nil { |
| 131 | log.Error("解析统一用户中心响应失败 err:%s", err) | 131 | log.Error("解析统一用户中心响应失败 err:%s", err) |
| 132 | return nil, protocol.NewErrWithMessage("1") | 132 | return nil, protocol.NewErrWithMessage("1") |
| @@ -134,7 +134,7 @@ func RequestUCenterSmsCodeCheck(phone string, captcha string) (*ResponseSmsCodeC | @@ -134,7 +134,7 @@ func RequestUCenterSmsCodeCheck(phone string, captcha string) (*ResponseSmsCodeC | ||
| 134 | if !(ucenterReturn.Code == ResponseCode0) { | 134 | if !(ucenterReturn.Code == ResponseCode0) { |
| 135 | return nil, protocol.NewErrWithMessage("10026") | 135 | return nil, protocol.NewErrWithMessage("10026") |
| 136 | } | 136 | } |
| 137 | - return ucenterReturn, nil | 137 | + return &ucenterReturn, nil |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | func RequestUCenterRestPassword(phone, newPwd, confirmPwd, certificate string) error { | 140 | func RequestUCenterRestPassword(phone, newPwd, confirmPwd, certificate string) error { |
-
请 注册 或 登录 后发表评论