Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/oppmg into dev
正在显示
12 个修改的文件
包含
244 行增加
和
42 行删除
| @@ -8,6 +8,7 @@ import ( | @@ -8,6 +8,7 @@ import ( | ||
| 8 | serveaudit "oppmg/services/audit" | 8 | serveaudit "oppmg/services/audit" |
| 9 | servecommon "oppmg/services/common" | 9 | servecommon "oppmg/services/common" |
| 10 | "strconv" | 10 | "strconv" |
| 11 | + "time" | ||
| 11 | ) | 12 | ) |
| 12 | 13 | ||
| 13 | type AuditController struct { | 14 | type AuditController struct { |
| @@ -27,6 +28,14 @@ func (c *AuditController) AuditList() { | @@ -27,6 +28,14 @@ func (c *AuditController) AuditList() { | ||
| 27 | msg = protocol.BadRequestParam("1") | 28 | msg = protocol.BadRequestParam("1") |
| 28 | return | 29 | return |
| 29 | } | 30 | } |
| 31 | + beginTime, err := time.Parse("2006-01-02", param.CreateTimeBeginS) | ||
| 32 | + if err == nil && len(param.CreateTimeBeginS) > 0 { | ||
| 33 | + param.CreateTimeBegin = beginTime.Unix() | ||
| 34 | + } | ||
| 35 | + endTime, err := time.Parse("2006-01-02", param.CreateTimeEndS) | ||
| 36 | + if err == nil && len(param.CreateTimeEndS) > 0 { | ||
| 37 | + param.CreateTimeEnd = endTime.Unix() + 864399 | ||
| 38 | + } | ||
| 30 | uid := c.GetUserId() | 39 | uid := c.GetUserId() |
| 31 | companyId := c.GetCompanyId() | 40 | companyId := c.GetCompanyId() |
| 32 | list, err := serveaudit.GetAuditList(param, companyId, uid) | 41 | list, err := serveaudit.GetAuditList(param, companyId, uid) |
| @@ -83,3 +92,33 @@ func (c *AuditController) AuditInfo() { | @@ -83,3 +92,33 @@ func (c *AuditController) AuditInfo() { | ||
| 83 | msg = protocol.NewReturnResponse(list, err) | 92 | msg = protocol.NewReturnResponse(list, err) |
| 84 | return | 93 | return |
| 85 | } | 94 | } |
| 95 | + | ||
| 96 | +//AllowForbidAudit 开启、关闭 机会 | ||
| 97 | +//@router /v1/audit/allow_forbid | ||
| 98 | +func (c *AuditController) AllowForbidAudit() { | ||
| 99 | + var msg *protocol.ResponseMessage | ||
| 100 | + defer func() { | ||
| 101 | + c.ResposeJson(msg) | ||
| 102 | + }() | ||
| 103 | + type Parameter struct { | ||
| 104 | + ChanceId string `json:"chance_id"` | ||
| 105 | + Status int `json:"status"` //[1:开启机会][2:关闭机会] | ||
| 106 | + } | ||
| 107 | + var param Parameter | ||
| 108 | + if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
| 109 | + log.Error("json 解析失败", err) | ||
| 110 | + msg = protocol.BadRequestParam("1") | ||
| 111 | + return | ||
| 112 | + } | ||
| 113 | + chanceid, _ := strconv.ParseInt(param.ChanceId, 10, 64) | ||
| 114 | + companyId := c.GetCompanyId() | ||
| 115 | + var err error | ||
| 116 | + switch param.Status { | ||
| 117 | + case 1: | ||
| 118 | + err = serveaudit.AllowChanceEnableStatus(chanceid, companyId) | ||
| 119 | + case 2: | ||
| 120 | + err = serveaudit.ForbidChanceEnableStatus(chanceid, companyId) | ||
| 121 | + } | ||
| 122 | + msg = protocol.NewReturnResponse(nil, err) | ||
| 123 | + return | ||
| 124 | +} |
| @@ -28,8 +28,11 @@ func (this *BaseController) Prepare() { | @@ -28,8 +28,11 @@ func (this *BaseController) Prepare() { | ||
| 28 | this.Ctx.WriteString("") | 28 | this.Ctx.WriteString("") |
| 29 | return | 29 | return |
| 30 | } | 30 | } |
| 31 | - p := this.Ctx.Input.GetData("RouterPattern") | ||
| 32 | - fmt.Println("====>r:", p) | 31 | + // p := this.Ctx.Input.GetData("RouterPattern") |
| 32 | + // userid := this.GetUserId() | ||
| 33 | + // companyid := this.GetCompanyId() | ||
| 34 | + //权限校验 | ||
| 35 | + | ||
| 33 | } | 36 | } |
| 34 | 37 | ||
| 35 | func (this *BaseController) GetAppHead() (appHead protocol.BaseHeader) { | 38 | func (this *BaseController) GetAppHead() (appHead protocol.BaseHeader) { |
| @@ -117,6 +117,3 @@ var LogRouter = func(ctx *context.Context) { | @@ -117,6 +117,3 @@ var LogRouter = func(ctx *context.Context) { | ||
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | //CheckOperation 检查操作权限,beforeController | 119 | //CheckOperation 检查操作权限,beforeController |
| 120 | -var CheckOperation = func(ctx *context.Context) { | ||
| 121 | - | ||
| 122 | -} |
| @@ -71,13 +71,13 @@ var ChanceReviewStatusMap = map[int]string{ | @@ -71,13 +71,13 @@ var ChanceReviewStatusMap = map[int]string{ | ||
| 71 | 71 | ||
| 72 | //有效状态 0:无效 1:有效 | 72 | //有效状态 0:无效 1:有效 |
| 73 | const ( | 73 | const ( |
| 74 | - ChanceEnableStatusYes int = 1 | ||
| 75 | - ChanceEnableStatusNo int = 0 | 74 | + ChanceEnableStatusYes int8 = 1 |
| 75 | + ChanceEnableStatusNo int8 = 0 | ||
| 76 | ) | 76 | ) |
| 77 | 77 | ||
| 78 | -var ChanceEnableStatusMap = map[int]string{ | ||
| 79 | - 0: "无效", | ||
| 80 | - 1: "有效", | 78 | +var ChanceEnableStatusMap = map[int8]string{ |
| 79 | + ChanceEnableStatusNo: "无效", | ||
| 80 | + ChanceEnableStatusYes: "有效", | ||
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | // AddChance insert a new Chance into database and returns | 83 | // AddChance insert a new Chance into database and returns |
| @@ -236,9 +236,12 @@ type RequestAuditList struct { | @@ -236,9 +236,12 @@ type RequestAuditList struct { | ||
| 236 | ReviewStatus int `json:"review_status"` // | 236 | ReviewStatus int `json:"review_status"` // |
| 237 | EnableStatus int `json:"enable_status"` //关闭状态 | 237 | EnableStatus int `json:"enable_status"` //关闭状态 |
| 238 | DepartmentID int `json:"department_id"` //提交部门 | 238 | DepartmentID int `json:"department_id"` //提交部门 |
| 239 | - CreateTimeBegin int `json:"create_time_begin"` // | ||
| 240 | - CreateTimeEnd int `json:"create_time_end"` // | 239 | + CreateTimeBegin int64 `json:"-"` // |
| 240 | + CreateTimeBeginS string `json:"create_time_begin"` | ||
| 241 | + CreateTimeEnd int64 `json:"-"` // | ||
| 242 | + CreateTimeEndS string `json:"create_time_end"` // | ||
| 241 | Code string `json:"code"` //机会编码 | 243 | Code string `json:"code"` //机会编码 |
| 244 | + UserName string `json:"user_name"` //提交人姓名 | ||
| 242 | } | 245 | } |
| 243 | 246 | ||
| 244 | type ResponseAuditList struct { | 247 | type ResponseAuditList struct { |
| @@ -258,7 +261,7 @@ type RspAuditList struct { | @@ -258,7 +261,7 @@ type RspAuditList struct { | ||
| 258 | PublishStatusName string `json:"publish_status_name"` // | 261 | PublishStatusName string `json:"publish_status_name"` // |
| 259 | ReviewStatus int `json:"review_status"` //审批状态 | 262 | ReviewStatus int `json:"review_status"` //审批状态 |
| 260 | ReviewStatusName string `json:"review_status_name"` | 263 | ReviewStatusName string `json:"review_status_name"` |
| 261 | - EnableStatus int `json:"enable_status"` | 264 | + EnableStatus int8 `json:"enable_status"` |
| 262 | EnableStatusName string `json:"enable_status_name"` | 265 | EnableStatusName string `json:"enable_status_name"` |
| 263 | } | 266 | } |
| 264 | 267 |
| @@ -101,6 +101,7 @@ func init() { | @@ -101,6 +101,7 @@ func init() { | ||
| 101 | beego.NSRouter("/list", &controllers.AuditController{}, "post:AuditList"), | 101 | beego.NSRouter("/list", &controllers.AuditController{}, "post:AuditList"), |
| 102 | beego.NSRouter("/list/before", &controllers.AuditController{}, "post:AuditListBefore"), | 102 | beego.NSRouter("/list/before", &controllers.AuditController{}, "post:AuditListBefore"), |
| 103 | beego.NSRouter("/info", &controllers.AuditController{}, "post:AuditInfo"), | 103 | beego.NSRouter("/info", &controllers.AuditController{}, "post:AuditInfo"), |
| 104 | + beego.NSRouter("/allow_forbid", &controllers.AuditController{}, "post:AllowForbidAudit"), | ||
| 104 | ), | 105 | ), |
| 105 | ) | 106 | ) |
| 106 | 107 |
| @@ -20,11 +20,10 @@ type SqlData struct { | @@ -20,11 +20,10 @@ type SqlData struct { | ||
| 20 | PublishStatus int `orm:"column(publish_status)"` | 20 | PublishStatus int `orm:"column(publish_status)"` |
| 21 | CreateAt time.Time `orm:"column(create_at);type(timestamp)"` | 21 | CreateAt time.Time `orm:"column(create_at);type(timestamp)"` |
| 22 | ReviewStatus int `orm:"column(review_status)"` | 22 | ReviewStatus int `orm:"column(review_status)"` |
| 23 | - EnableStatus int `orm:"column(enable_status)"` | 23 | + EnableStatus int8 `orm:"column(enable_status)"` |
| 24 | DiscoveryScore string `orm:"column(discovery_score)"` | 24 | DiscoveryScore string `orm:"column(discovery_score)"` |
| 25 | CommentTotal string `orm:"column(comment_total)"` | 25 | CommentTotal string `orm:"column(comment_total)"` |
| 26 | Code string `orm:"column(code)"` | 26 | Code string `orm:"column(code)"` |
| 27 | - TemplateName string `orm:"column(template_name)"` | ||
| 28 | } | 27 | } |
| 29 | 28 | ||
| 30 | func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64) (protocol.ResponseAuditList, error) { | 29 | func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64) (protocol.ResponseAuditList, error) { |
| @@ -46,13 +45,13 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64 | @@ -46,13 +45,13 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64 | ||
| 46 | } | 45 | } |
| 47 | datasql.WriteString(`SELECT a.id,a.user_id,a.department_id,a.audit_template_id,a.chance_type_id | 46 | datasql.WriteString(`SELECT a.id,a.user_id,a.department_id,a.audit_template_id,a.chance_type_id |
| 48 | ,a.publish_status,a.create_at,a.review_status,a.enable_status | 47 | ,a.publish_status,a.create_at,a.review_status,a.enable_status |
| 49 | - ,a.discovery_score,a.comment_total,b.name AS template_name ,b.code | 48 | + ,a.discovery_score,a.comment_total ,a.code,d.nick_name |
| 50 | FROM chance AS a | 49 | FROM chance AS a |
| 51 | - JOIN audit_template AS b on a.audit_template_id = b.id | 50 | + JOIN user_company AS c ON c.id = a.user_id |
| 51 | + JOIN user AS d ON c.user_id = d.id | ||
| 52 | where a.company_id=? `) | 52 | where a.company_id=? `) |
| 53 | 53 | ||
| 54 | countsql.WriteString(`SELECT count(*) FROM chance as a | 54 | countsql.WriteString(`SELECT count(*) FROM chance as a |
| 55 | - JOIN audit_template AS b on a.audit_template_id = b.id | ||
| 56 | where a.company_id=? `) | 55 | where a.company_id=? `) |
| 57 | cond = append(cond, companyid) | 56 | cond = append(cond, companyid) |
| 58 | if param.ChanceTypeId > 0 { | 57 | if param.ChanceTypeId > 0 { |
| @@ -86,15 +85,27 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64 | @@ -86,15 +85,27 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64 | ||
| 86 | datasql.WriteString(s) | 85 | datasql.WriteString(s) |
| 87 | countsql.WriteString(s) | 86 | countsql.WriteString(s) |
| 88 | } | 87 | } |
| 89 | - if param.CreateTimeBegin > 0 && param.CreateTimeEnd > 0 { | ||
| 90 | - cond = append(cond, param.CreateTimeBegin, param.CreateTimeEnd) | ||
| 91 | - s := ` AND (UNIX_TIMESTAMP(a.create_at) BETWEEN ? AND ? ) ` | 88 | + if param.CreateTimeBegin > 0 { |
| 89 | + cond = append(cond, param.CreateTimeBegin) | ||
| 90 | + s := ` AND UNIX_TIMESTAMP(a.create_at)>=? ` | ||
| 91 | + datasql.WriteString(s) | ||
| 92 | + countsql.WriteString(s) | ||
| 93 | + } | ||
| 94 | + if param.CreateTimeEnd > 0 { | ||
| 95 | + cond = append(cond, param.CreateTimeEnd) | ||
| 96 | + s := ` AND UNIX_TIMESTAMP(a.create_at)<=? ` | ||
| 92 | datasql.WriteString(s) | 97 | datasql.WriteString(s) |
| 93 | countsql.WriteString(s) | 98 | countsql.WriteString(s) |
| 94 | } | 99 | } |
| 95 | if len(param.Code) > 0 { | 100 | if len(param.Code) > 0 { |
| 96 | - cond = append(cond, param.Code) | ||
| 97 | - s := ` And b.code=? ` | 101 | + cond = append(cond, "%"+param.Code+"%") |
| 102 | + s := ` And a.code like ? ` | ||
| 103 | + datasql.WriteString(s) | ||
| 104 | + countsql.WriteString(s) | ||
| 105 | + } | ||
| 106 | + if len(param.UserName) > 0 { | ||
| 107 | + cond = append(cond, "%"+param.UserName+"%") | ||
| 108 | + s := ` And d.nick_name like ? ` | ||
| 98 | datasql.WriteString(s) | 109 | datasql.WriteString(s) |
| 99 | countsql.WriteString(s) | 110 | countsql.WriteString(s) |
| 100 | } | 111 | } |
| @@ -124,7 +135,6 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64 | @@ -124,7 +135,6 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64 | ||
| 124 | ReviewStatus: v.ReviewStatus, | 135 | ReviewStatus: v.ReviewStatus, |
| 125 | ReviewStatusName: models.ChanceReviewStatusMap[v.ReviewStatus], | 136 | ReviewStatusName: models.ChanceReviewStatusMap[v.ReviewStatus], |
| 126 | Code: v.Code, | 137 | Code: v.Code, |
| 127 | - TemplateName: v.TemplateName, | ||
| 128 | } | 138 | } |
| 129 | 139 | ||
| 130 | if t < 0 { | 140 | if t < 0 { |
| @@ -141,6 +151,9 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64 | @@ -141,6 +151,9 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64 | ||
| 141 | if ct, err := models.GetChanceTypeById(v.ChanceTypeId); err == nil { | 151 | if ct, err := models.GetChanceTypeById(v.ChanceTypeId); err == nil { |
| 142 | item.ChanceType = ct.Name | 152 | item.ChanceType = ct.Name |
| 143 | } | 153 | } |
| 154 | + if tp, err := models.GetAuditTemplateById(v.AuditTemplateId); err == nil { | ||
| 155 | + item.TemplateName = tp.Name | ||
| 156 | + } | ||
| 144 | returnData.List = append(returnData.List, item) | 157 | returnData.List = append(returnData.List, item) |
| 145 | 158 | ||
| 146 | } | 159 | } |
| @@ -261,3 +274,51 @@ func getAuditFlowLog(chanceid int64) ([]protocol.ChanceFlowLog, error) { | @@ -261,3 +274,51 @@ func getAuditFlowLog(chanceid int64) ([]protocol.ChanceFlowLog, error) { | ||
| 261 | err = utils.ExecuteQueryAll(&flowLogs, datasql, chanceid) | 274 | err = utils.ExecuteQueryAll(&flowLogs, datasql, chanceid) |
| 262 | return flowLogs, err | 275 | return flowLogs, err |
| 263 | } | 276 | } |
| 277 | + | ||
| 278 | +func AllowChanceEnableStatus(chanceid int64, companyid int64) error { | ||
| 279 | + var ( | ||
| 280 | + err error | ||
| 281 | + chanceinfo *models.Chance | ||
| 282 | + ) | ||
| 283 | + chanceinfo, err = models.GetChanceById(chanceid) | ||
| 284 | + if err != nil { | ||
| 285 | + log.Error("获取机会数据失败:%s", err) | ||
| 286 | + return protocol.NewErrWithMessage("1") | ||
| 287 | + } | ||
| 288 | + if chanceinfo.CompanyId != companyid { | ||
| 289 | + log.Error("机会的公司不匹配") | ||
| 290 | + return protocol.NewErrWithMessage("1") | ||
| 291 | + } | ||
| 292 | + chanceinfo.EnableStatus = models.ChanceEnableStatusYes | ||
| 293 | + chanceinfo.UpdateAt = time.Now() | ||
| 294 | + err = models.UpdateChanceById(chanceinfo, []string{"EnableStatus", "UpdateAt"}) | ||
| 295 | + if err != nil { | ||
| 296 | + log.Error("更新机会数据失败:%s", err) | ||
| 297 | + return protocol.NewErrWithMessage("1") | ||
| 298 | + } | ||
| 299 | + return nil | ||
| 300 | +} | ||
| 301 | + | ||
| 302 | +func ForbidChanceEnableStatus(chanceid int64, companyid int64) error { | ||
| 303 | + var ( | ||
| 304 | + err error | ||
| 305 | + chanceinfo *models.Chance | ||
| 306 | + ) | ||
| 307 | + chanceinfo, err = models.GetChanceById(chanceid) | ||
| 308 | + if err != nil { | ||
| 309 | + log.Error("获取机会数据失败:%s", err) | ||
| 310 | + return protocol.NewErrWithMessage("1") | ||
| 311 | + } | ||
| 312 | + if chanceinfo.CompanyId != companyid { | ||
| 313 | + log.Error("机会的公司不匹配") | ||
| 314 | + return protocol.NewErrWithMessage("1") | ||
| 315 | + } | ||
| 316 | + chanceinfo.EnableStatus = models.ChanceEnableStatusNo | ||
| 317 | + chanceinfo.UpdateAt = time.Now() | ||
| 318 | + err = models.UpdateChanceById(chanceinfo, []string{"EnableStatus", "UpdateAt"}) | ||
| 319 | + if err != nil { | ||
| 320 | + log.Error("更新机会数据失败:%s", err) | ||
| 321 | + return protocol.NewErrWithMessage("1") | ||
| 322 | + } | ||
| 323 | + return nil | ||
| 324 | +} |
| @@ -8,6 +8,7 @@ import ( | @@ -8,6 +8,7 @@ import ( | ||
| 8 | "oppmg/common/log" | 8 | "oppmg/common/log" |
| 9 | "oppmg/models" | 9 | "oppmg/models" |
| 10 | "oppmg/protocol" | 10 | "oppmg/protocol" |
| 11 | + serverbac "oppmg/services/rbac" | ||
| 11 | "oppmg/services/ucenter" | 12 | "oppmg/services/ucenter" |
| 12 | "oppmg/storage/redisdata" | 13 | "oppmg/storage/redisdata" |
| 13 | "oppmg/utils" | 14 | "oppmg/utils" |
| @@ -237,6 +238,8 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro | @@ -237,6 +238,8 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro | ||
| 237 | if err != nil { | 238 | if err != nil { |
| 238 | log.Error("更新用户数据失败:%s", err) | 239 | log.Error("更新用户数据失败:%s", err) |
| 239 | } | 240 | } |
| 241 | + | ||
| 242 | + InitPermission(usercompanyid) | ||
| 240 | return logintoken, err | 243 | return logintoken, err |
| 241 | } | 244 | } |
| 242 | 245 | ||
| @@ -371,14 +374,21 @@ func GetUserHasMenu(userid, companyid int64) ([]protocol.ResponseUserHasMenu, er | @@ -371,14 +374,21 @@ func GetUserHasMenu(userid, companyid int64) ([]protocol.ResponseUserHasMenu, er | ||
| 371 | log.Error("EXECUTE SQL err:%s", err) | 374 | log.Error("EXECUTE SQL err:%s", err) |
| 372 | return nil, protocol.NewErrWithMessage("1") | 375 | return nil, protocol.NewErrWithMessage("1") |
| 373 | } | 376 | } |
| 377 | + paramMap := map[int64]bool{} | ||
| 374 | for i := range list { | 378 | for i := range list { |
| 375 | for _, v := range menuids { | 379 | for _, v := range menuids { |
| 376 | if list[i].Id == v { | 380 | if list[i].Id == v { |
| 377 | list[i].StatusYes() | 381 | list[i].StatusYes() |
| 382 | + paramMap[list[i].ParentId] = true | ||
| 378 | break | 383 | break |
| 379 | } | 384 | } |
| 380 | } | 385 | } |
| 381 | } | 386 | } |
| 387 | + for i := range list { | ||
| 388 | + if _, ok := paramMap[list[i].Id]; ok { | ||
| 389 | + list[i].StatusYes() | ||
| 390 | + } | ||
| 391 | + } | ||
| 382 | return list, nil | 392 | return list, nil |
| 383 | } | 393 | } |
| 384 | 394 | ||
| @@ -467,6 +477,7 @@ func LoginAuthBySmsCode(phone string, code string) (protocol.LoginAuthToken, err | @@ -467,6 +477,7 @@ func LoginAuthBySmsCode(phone string, code string) (protocol.LoginAuthToken, err | ||
| 467 | if err != nil { | 477 | if err != nil { |
| 468 | log.Error("更新用户数据失败:%s", err) | 478 | log.Error("更新用户数据失败:%s", err) |
| 469 | } | 479 | } |
| 480 | + InitPermission(usercompanyid) | ||
| 470 | return logintoken, err | 481 | return logintoken, err |
| 471 | } | 482 | } |
| 472 | 483 | ||
| @@ -495,3 +506,44 @@ func SmsCodeCheck(phone string, code string) error { | @@ -495,3 +506,44 @@ func SmsCodeCheck(phone string, code string) error { | ||
| 495 | redisdata.SetCaptchAuth(phone, resp.Data.CaptchaCertificate) | 506 | redisdata.SetCaptchAuth(phone, resp.Data.CaptchaCertificate) |
| 496 | return nil | 507 | return nil |
| 497 | } | 508 | } |
| 509 | + | ||
| 510 | +//InitPermission 登录时权限初始化 | ||
| 511 | +func InitPermission(usercompanyid int64) error { | ||
| 512 | + var ( | ||
| 513 | + err error | ||
| 514 | + permissionMap map[string]serverbac.PermissionOptionObject | ||
| 515 | + ) | ||
| 516 | + permissionMap, err = serverbac.GetUserPermission(usercompanyid) | ||
| 517 | + if err != nil { | ||
| 518 | + log.Error("获取用户的权限失败") | ||
| 519 | + return err | ||
| 520 | + } | ||
| 521 | + err = redisdata.SetUserPermission(permissionMap, usercompanyid) | ||
| 522 | + if err != nil { | ||
| 523 | + log.Error("缓存用户权限失败:%s", err) | ||
| 524 | + } | ||
| 525 | + return nil | ||
| 526 | +} | ||
| 527 | + | ||
| 528 | +func ValidUserPermission(urlPath string, userid int64, companyid int64) bool { | ||
| 529 | + var ( | ||
| 530 | + err error | ||
| 531 | + permissionbase serverbac.PermissionBase | ||
| 532 | + ok bool = false | ||
| 533 | + permissionObj serverbac.PermissionOptionObject | ||
| 534 | + ) | ||
| 535 | + permissionbase, ok = serverbac.RouterPermission[urlPath] | ||
| 536 | + if !ok { | ||
| 537 | + return true | ||
| 538 | + } | ||
| 539 | + permissionObj, err = redisdata.GetUserPermission(userid, permissionbase.CodeName) | ||
| 540 | + if err != nil { | ||
| 541 | + log.Error("未取到权限数据") | ||
| 542 | + return false | ||
| 543 | + } | ||
| 544 | + ok = permissionObj.GetValidFunc(permissionbase.ActionName) | ||
| 545 | + if ok { | ||
| 546 | + return true | ||
| 547 | + } | ||
| 548 | + return false | ||
| 549 | +} |
| @@ -25,7 +25,7 @@ const ( | @@ -25,7 +25,7 @@ const ( | ||
| 25 | type PermissionOptionObject interface { | 25 | type PermissionOptionObject interface { |
| 26 | // StringUnmarshal(string) error | 26 | // StringUnmarshal(string) error |
| 27 | // ObjectMarshal() string | 27 | // ObjectMarshal() string |
| 28 | - GetValidFunc(string) func(UserObject) bool | 28 | + GetValidFunc(string) bool |
| 29 | MergeObject(string) error | 29 | MergeObject(string) error |
| 30 | } | 30 | } |
| 31 | 31 | ||
| @@ -35,7 +35,7 @@ type PermissionBase struct { | @@ -35,7 +35,7 @@ type PermissionBase struct { | ||
| 35 | ActionName string | 35 | ActionName string |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | -var routerPermission = map[string]PermissionBase{ | 38 | +var RouterPermission = map[string]PermissionBase{ |
| 39 | "/v1/department/list": PermissionBase{CodeName: M_ENTERPRISE_ORGANIZATION, ActionName: "default"}, | 39 | "/v1/department/list": PermissionBase{CodeName: M_ENTERPRISE_ORGANIZATION, ActionName: "default"}, |
| 40 | "/v1/department/add": PermissionBase{CodeName: M_ENTERPRISE_ORGANIZATION, ActionName: "default"}, | 40 | "/v1/department/add": PermissionBase{CodeName: M_ENTERPRISE_ORGANIZATION, ActionName: "default"}, |
| 41 | "/v1/department/edit": PermissionBase{CodeName: M_ENTERPRISE_ORGANIZATION, ActionName: "default"}, | 41 | "/v1/department/edit": PermissionBase{CodeName: M_ENTERPRISE_ORGANIZATION, ActionName: "default"}, |
| @@ -133,7 +133,7 @@ func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, | @@ -133,7 +133,7 @@ func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, | ||
| 133 | if fn, ok := CodePermissionObject[v.Code]; ok { | 133 | if fn, ok := CodePermissionObject[v.Code]; ok { |
| 134 | obj := fn() | 134 | obj := fn() |
| 135 | if err = json.Unmarshal([]byte(v.Opption), obj); err != nil { | 135 | if err = json.Unmarshal([]byte(v.Opption), obj); err != nil { |
| 136 | - log.Debug("解析权限配置option 失败%s", err) | 136 | + log.Debug("解析权限配置option:%s %s失败%s", v.Code, v.Opption, err) |
| 137 | } | 137 | } |
| 138 | objMap[v.Code] = obj | 138 | objMap[v.Code] = obj |
| 139 | } else { | 139 | } else { |
| @@ -25,7 +25,7 @@ func NewPermissionOptionBase() PermissionOptionObject { | @@ -25,7 +25,7 @@ func NewPermissionOptionBase() PermissionOptionObject { | ||
| 25 | } | 25 | } |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | -func (p *PermissionOptionBase) ValidDefault(obj UserObject) bool { | 28 | +func (p *PermissionOptionBase) ValidDefault() bool { |
| 29 | if p.Check == 1 { | 29 | if p.Check == 1 { |
| 30 | return true | 30 | return true |
| 31 | } | 31 | } |
| @@ -33,14 +33,15 @@ func (p *PermissionOptionBase) ValidDefault(obj UserObject) bool { | @@ -33,14 +33,15 @@ func (p *PermissionOptionBase) ValidDefault(obj UserObject) bool { | ||
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | //GetValidFunc PermissionOptionBase 接口实现 | 35 | //GetValidFunc PermissionOptionBase 接口实现 |
| 36 | -func (p *PermissionOptionBase) GetValidFunc(k string) func(UserObject) bool { | ||
| 37 | - m := map[string]func(UserObject) bool{ | 36 | +func (p *PermissionOptionBase) GetValidFunc(k string) bool { |
| 37 | + m := map[string]func() bool{ | ||
| 38 | "default": p.ValidDefault, | 38 | "default": p.ValidDefault, |
| 39 | } | 39 | } |
| 40 | - if _, ok := m[k]; ok { | ||
| 41 | - return m[k] | 40 | + if fn, ok := m[k]; ok { |
| 41 | + b := fn() | ||
| 42 | + return b | ||
| 42 | } | 43 | } |
| 43 | - return nil | 44 | + return false |
| 44 | } | 45 | } |
| 45 | 46 | ||
| 46 | func (p *PermissionOptionBase) MergeObject(jsonString string) error { | 47 | func (p *PermissionOptionBase) MergeObject(jsonString string) error { |
| @@ -94,7 +95,7 @@ type CheckOpp struct { | @@ -94,7 +95,7 @@ type CheckOpp struct { | ||
| 94 | //OptionOpportunity 机会管理 高级权限设置 | 95 | //OptionOpportunity 机会管理 高级权限设置 |
| 95 | type OptionOpportunity struct { | 96 | type OptionOpportunity struct { |
| 96 | Check int `json:"check"` | 97 | Check int `json:"check"` |
| 97 | - CheckMap map[int]int `json:"-"` | 98 | + CheckMap map[int]int `json:"check_map,omitempty"` |
| 98 | CheckOption CheckOpp `json:"check_option"` | 99 | CheckOption CheckOpp `json:"check_option"` |
| 99 | EditSorce int `json:"edit_sorce"` | 100 | EditSorce int `json:"edit_sorce"` |
| 100 | EditPublicStatus int `json:"edit_public_status"` | 101 | EditPublicStatus int `json:"edit_public_status"` |
| @@ -131,14 +132,15 @@ func NewOptionOpportunity() PermissionOptionObject { | @@ -131,14 +132,15 @@ func NewOptionOpportunity() PermissionOptionObject { | ||
| 131 | } | 132 | } |
| 132 | 133 | ||
| 133 | //GetValidFunc PermissionOptionBase 接口实现 | 134 | //GetValidFunc PermissionOptionBase 接口实现 |
| 134 | -func (p *OptionOpportunity) GetValidFunc(k string) func(UserObject) bool { | ||
| 135 | - m := map[string]func(UserObject) bool{ | 135 | +func (p *OptionOpportunity) GetValidFunc(k string) bool { |
| 136 | + m := map[string]func() bool{ | ||
| 136 | "check": p.ValidCheck, | 137 | "check": p.ValidCheck, |
| 137 | } | 138 | } |
| 138 | - if _, ok := m[k]; ok { | ||
| 139 | - return m[k] | 139 | + if fn, ok := m[k]; ok { |
| 140 | + b := fn() | ||
| 141 | + return b | ||
| 140 | } | 142 | } |
| 141 | - return nil | 143 | + return false |
| 142 | } | 144 | } |
| 143 | 145 | ||
| 144 | //MergeObject PermissionOptionBase 接口实现 | 146 | //MergeObject PermissionOptionBase 接口实现 |
| @@ -195,20 +197,20 @@ func (p *OptionOpportunity) MergeObject(jsonString string) error { | @@ -195,20 +197,20 @@ func (p *OptionOpportunity) MergeObject(jsonString string) error { | ||
| 195 | return nil | 197 | return nil |
| 196 | } | 198 | } |
| 197 | 199 | ||
| 198 | -func (p *OptionOpportunity) ValidCheck(obj UserObject) bool { | 200 | +func (p *OptionOpportunity) ValidCheck() bool { |
| 199 | if p.Check > 0 { | 201 | if p.Check > 0 { |
| 200 | return true | 202 | return true |
| 201 | } | 203 | } |
| 202 | return false | 204 | return false |
| 203 | } | 205 | } |
| 204 | 206 | ||
| 205 | -func (p *OptionOpportunity) ValidEditSorce(obj UserObject) bool { | 207 | +func (p *OptionOpportunity) ValidEditSorce() bool { |
| 206 | if p.EditSorce > 0 { | 208 | if p.EditSorce > 0 { |
| 207 | return true | 209 | return true |
| 208 | } | 210 | } |
| 209 | return false | 211 | return false |
| 210 | } | 212 | } |
| 211 | -func (p *OptionOpportunity) ValidEditPublicStatus(obj UserObject) bool { | 213 | +func (p *OptionOpportunity) ValidEditPublicStatus() bool { |
| 212 | if p.EditPublicStatus > 0 { | 214 | if p.EditPublicStatus > 0 { |
| 213 | return true | 215 | return true |
| 214 | } | 216 | } |
| @@ -9,6 +9,7 @@ const ( | @@ -9,6 +9,7 @@ const ( | ||
| 9 | KEY_PREFIX string = "oppmg_" //统一前缀 | 9 | KEY_PREFIX string = "oppmg_" //统一前缀 |
| 10 | KEY_USER_TOKEN string = "token" //登录token存储 | 10 | KEY_USER_TOKEN string = "token" //登录token存储 |
| 11 | KEY_CAPTCHA_AUTH string = "captch_auth" //统一用户中心返回的验证码凭证 | 11 | KEY_CAPTCHA_AUTH string = "captch_auth" //统一用户中心返回的验证码凭证 |
| 12 | + KEY_USER_PERMISSION string = "user_permission" //用户操作权限 | ||
| 12 | ) | 13 | ) |
| 13 | 14 | ||
| 14 | const ( | 15 | const ( |
| @@ -31,3 +32,8 @@ func GetKeyCaptchAuth(phone string) string { | @@ -31,3 +32,8 @@ func GetKeyCaptchAuth(phone string) string { | ||
| 31 | key := fmt.Sprintf("%s%s:%s", KEY_PREFIX, KEY_CAPTCHA_AUTH, phone) | 32 | key := fmt.Sprintf("%s%s:%s", KEY_PREFIX, KEY_CAPTCHA_AUTH, phone) |
| 32 | return key | 33 | return key |
| 33 | } | 34 | } |
| 35 | + | ||
| 36 | +func GetKeyUserPermission(userid int64) string { | ||
| 37 | + key := fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_PERMISSION, userid) | ||
| 38 | + return key | ||
| 39 | +} |
| @@ -2,10 +2,13 @@ package redisdata | @@ -2,10 +2,13 @@ package redisdata | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "encoding/json" | 4 | "encoding/json" |
| 5 | + "errors" | ||
| 5 | "oppmg/common/log" | 6 | "oppmg/common/log" |
| 6 | "oppmg/common/redis" | 7 | "oppmg/common/redis" |
| 7 | "oppmg/protocol" | 8 | "oppmg/protocol" |
| 9 | + "oppmg/services/rbac" | ||
| 8 | "strings" | 10 | "strings" |
| 11 | + "time" | ||
| 9 | ) | 12 | ) |
| 10 | 13 | ||
| 11 | func SetLoginToken(param protocol.LoginAuthToken, userid int64, companyid int64) error { | 14 | func SetLoginToken(param protocol.LoginAuthToken, userid int64, companyid int64) error { |
| @@ -96,3 +99,38 @@ func GetCaptchAuth(phone string) (string, error) { | @@ -96,3 +99,38 @@ func GetCaptchAuth(phone string) (string, error) { | ||
| 96 | r, err := client.Get(key).Result() | 99 | r, err := client.Get(key).Result() |
| 97 | return r, err | 100 | return r, err |
| 98 | } | 101 | } |
| 102 | + | ||
| 103 | +func SetUserPermission(objMap map[string]rbac.PermissionOptionObject, usercompanyid int64) error { | ||
| 104 | + key := GetKeyUserPermission(usercompanyid) | ||
| 105 | + client := redis.GetRedis() | ||
| 106 | + for k := range objMap { | ||
| 107 | + s, err := json.Marshal(objMap[k]) | ||
| 108 | + if err != nil { | ||
| 109 | + log.Error("解析错误:%s", err) | ||
| 110 | + continue | ||
| 111 | + } | ||
| 112 | + err = client.HSet(key, k, s).Err() | ||
| 113 | + if err != nil { | ||
| 114 | + log.Error("设置权限缓存失败:%s", err) | ||
| 115 | + } | ||
| 116 | + } | ||
| 117 | + client.Expire(key, 60*60*6*time.Second) | ||
| 118 | + return nil | ||
| 119 | +} | ||
| 120 | + | ||
| 121 | +func GetUserPermission(userid int64, field string) (rbac.PermissionOptionObject, error) { | ||
| 122 | + key := GetKeyUserPermission(userid) | ||
| 123 | + client := redis.GetRedis() | ||
| 124 | + str, err := client.HGet(key, field).Result() | ||
| 125 | + if err != nil { | ||
| 126 | + return nil, err | ||
| 127 | + } | ||
| 128 | + var permissionObj rbac.PermissionOptionObject | ||
| 129 | + fn, ok := rbac.CodePermissionObject[field] | ||
| 130 | + if !ok { | ||
| 131 | + return nil, errors.New("cannot get object") | ||
| 132 | + } | ||
| 133 | + permissionObj = fn() | ||
| 134 | + err = json.Unmarshal([]byte(str), permissionObj) | ||
| 135 | + return permissionObj, err | ||
| 136 | +} |
-
请 注册 或 登录 后发表评论