作者 唐旭辉

bug fix

package controllers
import (
"encoding/json"
"fmt"
"oppmg/protocol"
serverbac "oppmg/services/rbac"
)
type AuditController struct {
... ... @@ -10,10 +13,10 @@ type AuditController struct {
//AuditList 机会管理列表
//@router /v1/audit/list [post]
func (this *AuditController) AuditList() {
func (c *AuditController) AuditList() {
var msg *protocol.ResponseMessage
defer func() {
this.ResposeJson(msg)
c.ResposeJson(msg)
}()
// var request *protocol.ConfigScoreRequest
// if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
... ... @@ -26,3 +29,9 @@ func (this *AuditController) AuditList() {
msg = protocol.NewReturnResponse(nil, nil)
return
}
func (c *AuditController) Test() {
data, _ := serverbac.GetUserPermission(1)
bt, _ := json.Marshal(data)
fmt.Println(string(bt))
}
... ...
... ... @@ -23,7 +23,7 @@ var LogRequestData = func(ctx *context.Context) {
//protocol.HeaderRefreshToken: ctx.Input.Header(protocol.HeaderRefreshToken),
}
if ctx.Input.RequestBody != nil {
log.Info("====>Recv data from client:\nHeadData: %v \nBodyData: %s", hmap, string(ctx.Input.RequestBody))
log.Info("====>Recv data from client:\nHeadData: %v \nBodyData: %s", hmap, string(ctx.Input.RequestBody[0:2000]))
} else {
log.Info("====>Recv data from client:\nHeadData: %v ", hmap)
}
... ...
... ... @@ -129,4 +129,5 @@ func init() {
beego.SetStaticPath("/log", beego.AppConfig.String("log_filename"))
beego.SetStaticPath("/file/opp", beego.AppConfig.String("file_save_path"))
beego.SetStaticPath("/static", "./static")
beego.NSRouter("/test", &controllers.AuditController{}, "get:Test")
}
... ...
package rbac
import (
"encoding/json"
"fmt"
"oppmg/common/log"
"oppmg/utils"
)
//模块编号
const (
M_ENTERPRISE string = "ENTERPRISE" //企业基础设置
... ... @@ -44,3 +51,40 @@ var CodePermissionObject = map[string]CodeToObject{
M_SYSTEM_RATING: NewPermissionOptionBase, //评分模式
M_SYSTEM_OPPORTUNITY: NewPermissionOptionBase, //机会管理
}
func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, error) {
type CodeOpptionData struct {
Code string `orm:"column(code)"`
Opption string `orm:"column(opption)"`
}
const datasql string = `SELECT a.code,a.opption
FROM role_menu AS a
JOIN user_role AS b ON a.role_id = b.role_id
JOIN role AS c ON a.role_id = c.id
WHERE b.user_company_id=31 AND c.delete_at =0`
var (
data []CodeOpptionData
err error
objMap = make(map[string]PermissionOptionObject)
)
err = utils.ExecuteQueryAll(&data, datasql, userCompanyid)
if err != nil {
e := fmt.Errorf("EXCUTE SQL ERR:%s", err)
return nil, e
}
for _, v := range data {
if _, ok := objMap[v.Code]; ok {
err = objMap[v.Code].MergeObject(v.Opption)
if err != nil {
log.Warn(err.Error())
}
continue
}
obj := CodePermissionObject[v.Code]()
if err = json.Unmarshal([]byte(v.Opption), obj); err != nil {
log.Debug("解析权限配置option 失败%s", err)
}
objMap[v.Code] = obj
}
return objMap, nil
}
... ...
... ... @@ -42,12 +42,14 @@ func (p *PermissionOptionBase) GetValidFunc(k string) func(UserObject) bool {
}
func (p *PermissionOptionBase) MergeObject(jsonString string) error {
var obj PermissionBase
var obj PermissionOptionBase
err := json.Unmarshal([]byte(jsonString), &obj)
if err != nil {
return err
}
// if o
if obj.Check > p.Check {
p.Check = obj.Check
}
return nil
}
... ... @@ -89,11 +91,13 @@ type CheckOpp struct {
//OptionOpportunity 机会管理 高级权限设置
type OptionOpportunity struct {
Check int `json:"check"`
CheckOption CheckOpp `json:"check_option"`
EditSorce int `json:"edit_sorce"`
EditPublicStatus int `json:"edit_public_status"`
CloseChance int `json:"close_chance"`
Check int `json:"check"`
CheckMap map[int]int `json:"-"`
CheckOption CheckOpp `json:"check_option"`
EditSorce int `json:"edit_sorce"`
EditPublicStatus int `json:"edit_public_status"`
CloseChance int `json:"close_chance"`
EditChance int `json:"edit_chance"`
}
/*
... ... @@ -116,6 +120,7 @@ var (
func NewOptionOpportunity() PermissionOptionObject {
return &OptionOpportunity{
CheckMap: make(map[int]int),
CheckOption: CheckOpp{
Departments: []CheckDeparment{},
},
... ... @@ -134,7 +139,56 @@ func (p *OptionOpportunity) GetValidFunc(k string) func(UserObject) bool {
}
//MergeObject PermissionOptionBase 接口实现
func (p *OptionOpportunity) MergeObject(string) error {
func (p *OptionOpportunity) MergeObject(jsonString string) error {
var obj OptionOpportunity
err := json.Unmarshal([]byte(jsonString), &obj)
if err != nil {
return err
}
if p.CheckMap == nil {
p.CheckMap = make(map[int]int)
}
p.CheckMap[obj.Check] = 1
departMap := make(map[int64]*CheckDeparment)
for k := range p.CheckOption.Departments {
i := p.CheckOption.Departments[k].Id
departMap[i] = &p.CheckOption.Departments[k]
}
//列表合并
for k := range obj.CheckOption.Departments {
i := obj.CheckOption.Departments[k].Id
if _, ok := departMap[i]; ok {
if obj.CheckOption.Departments[k].OpenAll > departMap[i].OpenAll {
departMap[i].OpenAll = obj.CheckOption.Departments[k].OpenAll
}
if obj.CheckOption.Departments[k].OpenDepart > departMap[i].OpenDepart {
departMap[i].OpenDepart = obj.CheckOption.Departments[k].OpenDepart
}
if obj.CheckOption.Departments[k].Wait > departMap[i].Wait {
departMap[i].Wait = obj.CheckOption.Departments[k].Wait
}
} else {
departMap[i] = &obj.CheckOption.Departments[k]
}
}
p.CheckOption.Departments = make([]CheckDeparment, 0)
for k := range departMap {
p.CheckOption.Departments = append(p.CheckOption.Departments, *departMap[k])
}
if obj.CloseChance > p.CloseChance {
p.CloseChance = obj.CloseChance
}
if obj.EditPublicStatus > p.EditPublicStatus {
p.EditPublicStatus = obj.EditPublicStatus
}
if obj.EditSorce > p.EditSorce {
p.EditSorce = obj.EditSorce
}
if obj.EditChance > p.EditChance {
p.EditChance = obj.EditChance
}
return nil
}
... ...
... ... @@ -125,8 +125,8 @@ func RequestUCenterSmsCodeCheck(phone string, captcha string) (*ResponseSmsCodeC
log.Error("统一用户中心请求失败 err:%s", err)
return nil, protocol.NewErrWithMessage("1")
}
var ucenterReturn *ResponseSmsCodeCheck
err = json.Unmarshal(btBody, ucenterReturn)
var ucenterReturn ResponseSmsCodeCheck
err = json.Unmarshal(btBody, &ucenterReturn)
if err != nil {
log.Error("解析统一用户中心响应失败 err:%s", err)
return nil, protocol.NewErrWithMessage("1")
... ... @@ -134,7 +134,7 @@ func RequestUCenterSmsCodeCheck(phone string, captcha string) (*ResponseSmsCodeC
if !(ucenterReturn.Code == ResponseCode0) {
return nil, protocol.NewErrWithMessage("10026")
}
return ucenterReturn, nil
return &ucenterReturn, nil
}
func RequestUCenterRestPassword(phone, newPwd, confirmPwd, certificate string) error {
... ...