作者 唐旭辉

提交

... ... @@ -31,7 +31,9 @@ func (c *AuditController) AuditList() {
}
func (c *AuditController) Test() {
data, _ := serverbac.GetUserPermission(1)
bt, _ := json.Marshal(data)
data, err := serverbac.GetUserPermission(11)
fmt.Println(err)
bt, err := json.Marshal(data)
fmt.Println(err)
fmt.Println(string(bt))
}
... ...
... ... @@ -23,7 +23,12 @@ var LogRequestData = func(ctx *context.Context) {
//protocol.HeaderRefreshToken: ctx.Input.Header(protocol.HeaderRefreshToken),
}
if ctx.Input.RequestBody != nil {
if len(ctx.Input.RequestBody) > 1000 {
log.Info("====>Recv data from client:\nHeadData: %v \nBodyData: %s", hmap, string(ctx.Input.RequestBody[0:1000]))
} else {
log.Info("====>Recv data from client:\nHeadData: %v \nBodyData: %s", hmap, string(ctx.Input.RequestBody))
}
} else {
log.Info("====>Recv data from client:\nHeadData: %v ", hmap)
}
... ...
... ... @@ -30,8 +30,13 @@ var (
// AddSysConfig insert a new SysConfig into database and returns
// last inserted Id on success.
func AddSysConfig(m *SysConfig) (id int64, err error) {
o := orm.NewOrm()
func AddSysConfig(m *SysConfig, om ...orm.Ormer) (id int64, err error) {
var o orm.Ormer
if len(om) > 0 {
o = om[0]
} else {
o = orm.NewOrm()
}
id, err = o.Insert(m)
return
}
... ... @@ -49,16 +54,18 @@ func GetSysConfigById(id int) (v *SysConfig, err error) {
// UpdateSysConfig updates SysConfig by Id and returns error if
// the record to be updated doesn't exist
func UpdateSysConfigById(m *SysConfig) (err error) {
o := orm.NewOrm()
v := SysConfig{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
func UpdateSysConfigById(m *SysConfig, col []string, om ...orm.Ormer) (err error) {
var o orm.Ormer
if len(om) > 0 {
o = om[0]
} else {
o = orm.NewOrm()
}
var num int64
if num, err = o.Update(m); err == nil {
if num, err = o.Update(m, col...); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
... ...
... ... @@ -62,8 +62,7 @@ type ResponseMeInfo struct {
Companyid int64 `json:"company_id"`
Companyname string `json:"company_name"`
Logo string `json:"logo"`
Companys []MeCompany `json:"-"`
// Menu
AdminType int `json:"admin_type"`
}
type MeCompany struct {
... ...
package routers
import (
"encoding/json"
)
//PermissionBase 路由对应的权限
type PermissionBase struct {
CodeName string //模块标识
ActionName string
// MethodMap map[string]func()
}
var routerPermission = map[string]PermissionBase{
"/v1/department/list": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "check"},
"/v1/department/add": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "add"},
"/v1/department/edit": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "edit"},
"/v1/department/delete": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "delete"},
}
var permissionObject = map[string]interface{}{
"": 0,
}
//模块编号
const (
MENU_DEPARTMENT string = "OPPMG_DEPARTMENT" //公司部门管理模块
MENU_POSITION string = "OPPMG_POSITION" //公司职务管理
MENU_RBAC string = "OPPMG_RBAC" //员工角色/权限设置
MENU_USER string = "OPPMG_USER" //公司员工管理
MENU_ENTERPRISE_BASIC string = "OPPMG_ENTERPRISE_BASIC" //企业基础设置(大节点)
MENU_SYSTEM_FUNCTION string = "OPPMG_SYSTEM_FUNCTION" //系统功能(大节点)
MENU_CONMPANY string = "OPPMG_CONMPANY" //企业信息维护
MENU_CHANCE_TEMP string = "OPPMG_CHANCE_TEMP" //机会模板管理
MENU_SORCE string = "OPPMG_SORCE" //评分模式
MENU_CHANCE string = "OPPMG_CHANCE" //机会管理
)
type PermissionContentObject interface {
StringUnmarshal(string) error
ObjectMarshal() (string, error)
}
type PermissionContentBase struct {
Check int8 `json:"check"`
}
func NewPermissionContentBase() PermissionContentObject {
return &PermissionContentBase{}
}
func (p *PermissionContentBase) StringUnmarshal(s string) error {
err := json.Unmarshal([]byte(s), p)
return err
}
func (p *PermissionContentBase) ObjectMarshal() (string, error) {
bt, err := json.Marshal(p)
if err != nil {
return "", err
}
return string(bt), err
}
type CodeToObject func() PermissionContentObject
var CodePermissionObject = map[string]CodeToObject{
MENU_DEPARTMENT: NewPermissionContentBase, //公司部门管理模块
MENU_POSITION: NewPermissionContentBase, //公司职务管理
MENU_RBAC: NewPermissionContentBase, //员工角色/权限设置
MENU_USER: NewPermissionContentBase, //公司员工管理
MENU_ENTERPRISE_BASIC: NewPermissionContentBase, //企业基础设置(大节点)
MENU_SYSTEM_FUNCTION: NewPermissionContentBase, //系统功能(大节点)
MENU_CONMPANY: NewPermissionContentBase, //企业信息维护
MENU_CHANCE_TEMP: NewPermissionContentBase, //机会模板管理
MENU_SORCE: NewPermissionContentBase, //评分模式
MENU_CHANCE: NewPermissionContentBase, //机会管理
}
... ... @@ -129,5 +129,6 @@ 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")
beego.Router("/test", &controllers.AuditController{}, "get:Test")
}
... ...
... ... @@ -302,7 +302,11 @@ func UserBaseInfo(userid, companyid int64) (protocol.ResponseMeInfo, error) {
Companyname: currentCompany.Name,
Logo: currentCompany.Logo,
}
if currentCompany.AdminId == userinfo.Id {
meInfo.AdminType = 1 //公司账户主管
} else {
meInfo.AdminType = 2 //非公司账户主管
}
return meInfo, nil
}
... ...
package company
import (
"encoding/json"
"fmt"
"oppmg/common/log"
"oppmg/models"
... ... @@ -40,6 +41,12 @@ func InitCompanyInfo(centerCompany protocol.CenterCompanyInfo) error {
log.Error("处理公司数据失败:%s", err)
return protocol.NewErrWithMessage("1")
}
err = iniSysConfig(int(newCompany.Id), o)
if err != nil {
o.Rollback()
log.Error("处理评分配置数据失败:%s", err)
return protocol.NewErrWithMessage("1")
}
//添加user_company
newUserCompany, err = initUserCompany(newCompany, newUser, o)
if err != nil {
... ... @@ -397,6 +404,53 @@ func initUserRole(newUserCompany *models.UserCompany, newRole *models.Role, o or
return newUserRole, nil
}
func iniSysConfig(companyid int, o orm.Ormer) error {
var (
m *models.SysConfig
err error
)
m, err = models.GetSysConfigByCompanyId(companyid, models.KeyScore)
if err == nil {
return nil
}
v := protocol.ScoreConfig{
DiscoveryScore: &protocol.DiscoveryScore{
BasicFactor: 1,
ExtraFactor: 1,
ValueFactor: 1,
},
SumScore: &protocol.SumScore{
DiscoveryFactor: 1,
CatchFactor: 1,
},
BasicScore: &protocol.ScoreRange{
Max: 10000,
Min: 0,
Step: 1,
},
ExtraScore: &protocol.ScoreRange{
Max: 10000,
Min: 0,
Step: 1,
},
ValueScore: &protocol.ScoreRange{
Max: 10000,
Min: 0,
Step: 1,
},
}
bt, _ := json.Marshal(v)
m = &models.SysConfig{
Key: models.KeyScore,
CompanyId: companyid,
CreateAt: time.Now(),
UpdateAt: time.Now(),
Content: string(bt),
}
_, err = models.AddSysConfig(m, o)
return err
}
func CompanyInfoEdit(companyid int64, logo string) error {
data := models.Company{
Id: companyid,
... ...
... ... @@ -15,7 +15,7 @@ const (
M_ENTERPRISE_PROFILE string = "ENTERPRISE_PROFILE" //企业信息维护
M_ENTERPRISE_ORGANIZATION string = "ENTERPRISE_ORGANIZATION" //组织架构设置
M_ENTERPRISE_EMPLOYEE_POST string = "ENTERPRISE_EMPLOYEE-POST" //员工职位设置
M_ENTERPRISE_EMPLOYEE_ROLE string = "ENTERPRISE_EMPLOYEE_ROLE" //员工角色/权限设置
M_ENTERPRISE_EMPLOYEE_ROLE string = "ENTERPRISE_EMPLOYEE-ROLE" //员工角色/权限设置
M_ENTERPRISE_EMPLOYEE string = "ENTERPRISE_EMPLOYEE" //员工设置
M_SYSTEM_OPPORTUNITY_TEMPLATE string = "SYSTEM_OPPORTUNITY-TEMPLATE" //机会模板管理
M_SYSTEM_RATING string = "SYSTEM_RATING" //评分模式设置
... ... @@ -49,7 +49,8 @@ var CodePermissionObject = map[string]CodeToObject{
M_ENTERPRISE_PROFILE: NewPermissionOptionBase, //企业信息维护
M_SYSTEM_OPPORTUNITY_TEMPLATE: NewPermissionOptionBase, //机会模板管理
M_SYSTEM_RATING: NewPermissionOptionBase, //评分模式
M_SYSTEM_OPPORTUNITY: NewPermissionOptionBase, //机会管理
M_SYSTEM_OPPORTUNITY: NewOptionOpportunity, //机会管理
M_SYSTEM_ANNOUNCEMENT: NewPermissionOptionBase, //公告管理
}
func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, error) {
... ... @@ -61,7 +62,7 @@ func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject,
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`
WHERE b.user_company_id=? AND c.delete_at =0`
var (
data []CodeOpptionData
err error
... ... @@ -80,11 +81,16 @@ func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject,
}
continue
}
obj := CodePermissionObject[v.Code]()
if fn, ok := CodePermissionObject[v.Code]; ok {
obj := fn()
if err = json.Unmarshal([]byte(v.Opption), obj); err != nil {
log.Debug("解析权限配置option 失败%s", err)
}
objMap[v.Code] = obj
} else {
log.Error("未知code:%s", v.Code)
}
}
return objMap, nil
}
... ...
... ... @@ -9,7 +9,7 @@ import (
//RequestUCenterLogin 调用用户中心进行账号密码登录
func RequestUCenterLogin(account, password string) (*ResponseLogin, error) {
var uclientReturn *ResponseLogin
var uclientReturn ResponseLogin
param := RequesLogin{
Type: 1,
Phone: account,
... ... @@ -29,7 +29,7 @@ func RequestUCenterLogin(account, password string) (*ResponseLogin, error) {
if !(uclientReturn.Code == ResponseCode0) {
return nil, protocol.NewErrWithMessage("10052")
}
return uclientReturn, nil
return &uclientReturn, nil
}
//RequestUCenterAddUser 调用用户中心进行注册用户
... ... @@ -38,7 +38,7 @@ func RequestUCenterAddUser(phone string, nickname string, avatar string) (*Respo
if len(avatar) <= 0 {
avatar = config.MConfig.FileHost + "/static/avatar_default.png"
}
var ucenterReturn *ResponseAddUser
var ucenterReturn ResponseAddUser
param := RequestAddUser{
Phone: phone,
Nickname: nickname,
... ... @@ -60,7 +60,7 @@ func RequestUCenterAddUser(phone string, nickname string, avatar string) (*Respo
if !(ucenterReturn.Code == ResponseCode0) {
return nil, protocol.NewErrWithMessage("10052")
}
return ucenterReturn, nil
return &ucenterReturn, nil
}
//发送短信验证码
... ... @@ -150,8 +150,8 @@ func RequestUCenterRestPassword(phone, newPwd, confirmPwd, certificate string) e
log.Error("统一用户中心请求失败 err:%s", err)
return protocol.NewErrWithMessage("1")
}
var ucenterReturn *CommResponse
err = json.Unmarshal(btBody, ucenterReturn)
var ucenterReturn CommResponse
err = json.Unmarshal(btBody, &ucenterReturn)
if err != nil {
log.Error("解析统一用户中心响应失败 err:%s", err)
return protocol.NewErrWithMessage("1")
... ...