作者 唐旭辉

提交

@@ -31,7 +31,9 @@ func (c *AuditController) AuditList() { @@ -31,7 +31,9 @@ func (c *AuditController) AuditList() {
31 } 31 }
32 32
33 func (c *AuditController) Test() { 33 func (c *AuditController) Test() {
34 - data, _ := serverbac.GetUserPermission(1)  
35 - bt, _ := json.Marshal(data) 34 + data, err := serverbac.GetUserPermission(11)
  35 + fmt.Println(err)
  36 + bt, err := json.Marshal(data)
  37 + fmt.Println(err)
36 fmt.Println(string(bt)) 38 fmt.Println(string(bt))
37 } 39 }
@@ -23,7 +23,12 @@ var LogRequestData = func(ctx *context.Context) { @@ -23,7 +23,12 @@ 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 + if len(ctx.Input.RequestBody) > 1000 {
  27 + log.Info("====>Recv data from client:\nHeadData: %v \nBodyData: %s", hmap, string(ctx.Input.RequestBody[0:1000]))
  28 + } else {
  29 + log.Info("====>Recv data from client:\nHeadData: %v \nBodyData: %s", hmap, string(ctx.Input.RequestBody))
  30 + }
  31 +
27 } else { 32 } else {
28 log.Info("====>Recv data from client:\nHeadData: %v ", hmap) 33 log.Info("====>Recv data from client:\nHeadData: %v ", hmap)
29 } 34 }
@@ -30,8 +30,13 @@ var ( @@ -30,8 +30,13 @@ var (
30 30
31 // AddSysConfig insert a new SysConfig into database and returns 31 // AddSysConfig insert a new SysConfig into database and returns
32 // last inserted Id on success. 32 // last inserted Id on success.
33 -func AddSysConfig(m *SysConfig) (id int64, err error) {  
34 - o := orm.NewOrm() 33 +func AddSysConfig(m *SysConfig, om ...orm.Ormer) (id int64, err error) {
  34 + var o orm.Ormer
  35 + if len(om) > 0 {
  36 + o = om[0]
  37 + } else {
  38 + o = orm.NewOrm()
  39 + }
35 id, err = o.Insert(m) 40 id, err = o.Insert(m)
36 return 41 return
37 } 42 }
@@ -49,16 +54,18 @@ func GetSysConfigById(id int) (v *SysConfig, err error) { @@ -49,16 +54,18 @@ func GetSysConfigById(id int) (v *SysConfig, err error) {
49 54
50 // UpdateSysConfig updates SysConfig by Id and returns error if 55 // UpdateSysConfig updates SysConfig by Id and returns error if
51 // the record to be updated doesn't exist 56 // the record to be updated doesn't exist
52 -func UpdateSysConfigById(m *SysConfig) (err error) {  
53 - o := orm.NewOrm()  
54 - v := SysConfig{Id: m.Id}  
55 - // ascertain id exists in the database  
56 - if err = o.Read(&v); err == nil {  
57 - var num int64  
58 - if num, err = o.Update(m); err == nil {  
59 - fmt.Println("Number of records updated in database:", num)  
60 - } 57 +func UpdateSysConfigById(m *SysConfig, col []string, om ...orm.Ormer) (err error) {
  58 + var o orm.Ormer
  59 + if len(om) > 0 {
  60 + o = om[0]
  61 + } else {
  62 + o = orm.NewOrm()
61 } 63 }
  64 + var num int64
  65 + if num, err = o.Update(m, col...); err == nil {
  66 + fmt.Println("Number of records updated in database:", num)
  67 + }
  68 +
62 return 69 return
63 } 70 }
64 71
@@ -57,13 +57,12 @@ type ResponseSwapCompany struct { @@ -57,13 +57,12 @@ type ResponseSwapCompany struct {
57 57
58 //ResponseMeInfo 用户个人的me信息 58 //ResponseMeInfo 用户个人的me信息
59 type ResponseMeInfo struct { 59 type ResponseMeInfo struct {
60 - NickName string `json:"nick_name"`  
61 - Icon string `json:"icon"`  
62 - Companyid int64 `json:"company_id"`  
63 - Companyname string `json:"company_name"`  
64 - Logo string `json:"logo"`  
65 - Companys []MeCompany `json:"-"`  
66 - // Menu 60 + NickName string `json:"nick_name"`
  61 + Icon string `json:"icon"`
  62 + Companyid int64 `json:"company_id"`
  63 + Companyname string `json:"company_name"`
  64 + Logo string `json:"logo"`
  65 + AdminType int `json:"admin_type"`
67 } 66 }
68 67
69 type MeCompany struct { 68 type MeCompany struct {
1 -package routers  
2 -  
3 -import (  
4 - "encoding/json"  
5 -)  
6 -  
7 -//PermissionBase 路由对应的权限  
8 -type PermissionBase struct {  
9 - CodeName string //模块标识  
10 - ActionName string  
11 - // MethodMap map[string]func()  
12 -}  
13 -  
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)  
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 -}  
@@ -129,5 +129,6 @@ func init() { @@ -129,5 +129,6 @@ 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 + beego.Router("/test", &controllers.AuditController{}, "get:Test")
133 } 134 }
@@ -302,7 +302,11 @@ func UserBaseInfo(userid, companyid int64) (protocol.ResponseMeInfo, error) { @@ -302,7 +302,11 @@ func UserBaseInfo(userid, companyid int64) (protocol.ResponseMeInfo, error) {
302 Companyname: currentCompany.Name, 302 Companyname: currentCompany.Name,
303 Logo: currentCompany.Logo, 303 Logo: currentCompany.Logo,
304 } 304 }
305 - 305 + if currentCompany.AdminId == userinfo.Id {
  306 + meInfo.AdminType = 1 //公司账户主管
  307 + } else {
  308 + meInfo.AdminType = 2 //非公司账户主管
  309 + }
306 return meInfo, nil 310 return meInfo, nil
307 } 311 }
308 312
1 package company 1 package company
2 2
3 import ( 3 import (
  4 + "encoding/json"
4 "fmt" 5 "fmt"
5 "oppmg/common/log" 6 "oppmg/common/log"
6 "oppmg/models" 7 "oppmg/models"
@@ -40,6 +41,12 @@ func InitCompanyInfo(centerCompany protocol.CenterCompanyInfo) error { @@ -40,6 +41,12 @@ func InitCompanyInfo(centerCompany protocol.CenterCompanyInfo) error {
40 log.Error("处理公司数据失败:%s", err) 41 log.Error("处理公司数据失败:%s", err)
41 return protocol.NewErrWithMessage("1") 42 return protocol.NewErrWithMessage("1")
42 } 43 }
  44 + err = iniSysConfig(int(newCompany.Id), o)
  45 + if err != nil {
  46 + o.Rollback()
  47 + log.Error("处理评分配置数据失败:%s", err)
  48 + return protocol.NewErrWithMessage("1")
  49 + }
43 //添加user_company 50 //添加user_company
44 newUserCompany, err = initUserCompany(newCompany, newUser, o) 51 newUserCompany, err = initUserCompany(newCompany, newUser, o)
45 if err != nil { 52 if err != nil {
@@ -397,6 +404,53 @@ func initUserRole(newUserCompany *models.UserCompany, newRole *models.Role, o or @@ -397,6 +404,53 @@ func initUserRole(newUserCompany *models.UserCompany, newRole *models.Role, o or
397 return newUserRole, nil 404 return newUserRole, nil
398 } 405 }
399 406
  407 +func iniSysConfig(companyid int, o orm.Ormer) error {
  408 + var (
  409 + m *models.SysConfig
  410 + err error
  411 + )
  412 + m, err = models.GetSysConfigByCompanyId(companyid, models.KeyScore)
  413 + if err == nil {
  414 + return nil
  415 + }
  416 + v := protocol.ScoreConfig{
  417 + DiscoveryScore: &protocol.DiscoveryScore{
  418 + BasicFactor: 1,
  419 + ExtraFactor: 1,
  420 + ValueFactor: 1,
  421 + },
  422 + SumScore: &protocol.SumScore{
  423 + DiscoveryFactor: 1,
  424 + CatchFactor: 1,
  425 + },
  426 + BasicScore: &protocol.ScoreRange{
  427 + Max: 10000,
  428 + Min: 0,
  429 + Step: 1,
  430 + },
  431 + ExtraScore: &protocol.ScoreRange{
  432 + Max: 10000,
  433 + Min: 0,
  434 + Step: 1,
  435 + },
  436 + ValueScore: &protocol.ScoreRange{
  437 + Max: 10000,
  438 + Min: 0,
  439 + Step: 1,
  440 + },
  441 + }
  442 + bt, _ := json.Marshal(v)
  443 + m = &models.SysConfig{
  444 + Key: models.KeyScore,
  445 + CompanyId: companyid,
  446 + CreateAt: time.Now(),
  447 + UpdateAt: time.Now(),
  448 + Content: string(bt),
  449 + }
  450 + _, err = models.AddSysConfig(m, o)
  451 + return err
  452 +}
  453 +
400 func CompanyInfoEdit(companyid int64, logo string) error { 454 func CompanyInfoEdit(companyid int64, logo string) error {
401 data := models.Company{ 455 data := models.Company{
402 Id: companyid, 456 Id: companyid,
@@ -15,7 +15,7 @@ const ( @@ -15,7 +15,7 @@ const (
15 M_ENTERPRISE_PROFILE string = "ENTERPRISE_PROFILE" //企业信息维护 15 M_ENTERPRISE_PROFILE string = "ENTERPRISE_PROFILE" //企业信息维护
16 M_ENTERPRISE_ORGANIZATION string = "ENTERPRISE_ORGANIZATION" //组织架构设置 16 M_ENTERPRISE_ORGANIZATION string = "ENTERPRISE_ORGANIZATION" //组织架构设置
17 M_ENTERPRISE_EMPLOYEE_POST string = "ENTERPRISE_EMPLOYEE-POST" //员工职位设置 17 M_ENTERPRISE_EMPLOYEE_POST string = "ENTERPRISE_EMPLOYEE-POST" //员工职位设置
18 - M_ENTERPRISE_EMPLOYEE_ROLE string = "ENTERPRISE_EMPLOYEE_ROLE" //员工角色/权限设置 18 + M_ENTERPRISE_EMPLOYEE_ROLE string = "ENTERPRISE_EMPLOYEE-ROLE" //员工角色/权限设置
19 M_ENTERPRISE_EMPLOYEE string = "ENTERPRISE_EMPLOYEE" //员工设置 19 M_ENTERPRISE_EMPLOYEE string = "ENTERPRISE_EMPLOYEE" //员工设置
20 M_SYSTEM_OPPORTUNITY_TEMPLATE string = "SYSTEM_OPPORTUNITY-TEMPLATE" //机会模板管理 20 M_SYSTEM_OPPORTUNITY_TEMPLATE string = "SYSTEM_OPPORTUNITY-TEMPLATE" //机会模板管理
21 M_SYSTEM_RATING string = "SYSTEM_RATING" //评分模式设置 21 M_SYSTEM_RATING string = "SYSTEM_RATING" //评分模式设置
@@ -49,7 +49,8 @@ var CodePermissionObject = map[string]CodeToObject{ @@ -49,7 +49,8 @@ var CodePermissionObject = map[string]CodeToObject{
49 M_ENTERPRISE_PROFILE: NewPermissionOptionBase, //企业信息维护 49 M_ENTERPRISE_PROFILE: NewPermissionOptionBase, //企业信息维护
50 M_SYSTEM_OPPORTUNITY_TEMPLATE: NewPermissionOptionBase, //机会模板管理 50 M_SYSTEM_OPPORTUNITY_TEMPLATE: NewPermissionOptionBase, //机会模板管理
51 M_SYSTEM_RATING: NewPermissionOptionBase, //评分模式 51 M_SYSTEM_RATING: NewPermissionOptionBase, //评分模式
52 - M_SYSTEM_OPPORTUNITY: NewPermissionOptionBase, //机会管理 52 + M_SYSTEM_OPPORTUNITY: NewOptionOpportunity, //机会管理
  53 + M_SYSTEM_ANNOUNCEMENT: NewPermissionOptionBase, //公告管理
53 } 54 }
54 55
55 func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, error) { 56 func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, error) {
@@ -61,7 +62,7 @@ func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, @@ -61,7 +62,7 @@ func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject,
61 FROM role_menu AS a 62 FROM role_menu AS a
62 JOIN user_role AS b ON a.role_id = b.role_id 63 JOIN user_role AS b ON a.role_id = b.role_id
63 JOIN role AS c ON a.role_id = c.id 64 JOIN role AS c ON a.role_id = c.id
64 - WHERE b.user_company_id=31 AND c.delete_at =0` 65 + WHERE b.user_company_id=? AND c.delete_at =0`
65 var ( 66 var (
66 data []CodeOpptionData 67 data []CodeOpptionData
67 err error 68 err error
@@ -80,11 +81,16 @@ func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, @@ -80,11 +81,16 @@ func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject,
80 } 81 }
81 continue 82 continue
82 } 83 }
83 - obj := CodePermissionObject[v.Code]()  
84 - if err = json.Unmarshal([]byte(v.Opption), obj); err != nil {  
85 - log.Debug("解析权限配置option 失败%s", err) 84 + if fn, ok := CodePermissionObject[v.Code]; ok {
  85 + obj := fn()
  86 + if err = json.Unmarshal([]byte(v.Opption), obj); err != nil {
  87 + log.Debug("解析权限配置option 失败%s", err)
  88 + }
  89 + objMap[v.Code] = obj
  90 + } else {
  91 + log.Error("未知code:%s", v.Code)
86 } 92 }
87 - objMap[v.Code] = obj 93 +
88 } 94 }
89 return objMap, nil 95 return objMap, nil
90 } 96 }
@@ -9,7 +9,7 @@ import ( @@ -9,7 +9,7 @@ import (
9 9
10 //RequestUCenterLogin 调用用户中心进行账号密码登录 10 //RequestUCenterLogin 调用用户中心进行账号密码登录
11 func RequestUCenterLogin(account, password string) (*ResponseLogin, error) { 11 func RequestUCenterLogin(account, password string) (*ResponseLogin, error) {
12 - var uclientReturn *ResponseLogin 12 + var uclientReturn ResponseLogin
13 param := RequesLogin{ 13 param := RequesLogin{
14 Type: 1, 14 Type: 1,
15 Phone: account, 15 Phone: account,
@@ -29,7 +29,7 @@ func RequestUCenterLogin(account, password string) (*ResponseLogin, error) { @@ -29,7 +29,7 @@ func RequestUCenterLogin(account, password string) (*ResponseLogin, error) {
29 if !(uclientReturn.Code == ResponseCode0) { 29 if !(uclientReturn.Code == ResponseCode0) {
30 return nil, protocol.NewErrWithMessage("10052") 30 return nil, protocol.NewErrWithMessage("10052")
31 } 31 }
32 - return uclientReturn, nil 32 + return &uclientReturn, nil
33 } 33 }
34 34
35 //RequestUCenterAddUser 调用用户中心进行注册用户 35 //RequestUCenterAddUser 调用用户中心进行注册用户
@@ -38,7 +38,7 @@ func RequestUCenterAddUser(phone string, nickname string, avatar string) (*Respo @@ -38,7 +38,7 @@ func RequestUCenterAddUser(phone string, nickname string, avatar string) (*Respo
38 if len(avatar) <= 0 { 38 if len(avatar) <= 0 {
39 avatar = config.MConfig.FileHost + "/static/avatar_default.png" 39 avatar = config.MConfig.FileHost + "/static/avatar_default.png"
40 } 40 }
41 - var ucenterReturn *ResponseAddUser 41 + var ucenterReturn ResponseAddUser
42 param := RequestAddUser{ 42 param := RequestAddUser{
43 Phone: phone, 43 Phone: phone,
44 Nickname: nickname, 44 Nickname: nickname,
@@ -60,7 +60,7 @@ func RequestUCenterAddUser(phone string, nickname string, avatar string) (*Respo @@ -60,7 +60,7 @@ func RequestUCenterAddUser(phone string, nickname string, avatar string) (*Respo
60 if !(ucenterReturn.Code == ResponseCode0) { 60 if !(ucenterReturn.Code == ResponseCode0) {
61 return nil, protocol.NewErrWithMessage("10052") 61 return nil, protocol.NewErrWithMessage("10052")
62 } 62 }
63 - return ucenterReturn, nil 63 + return &ucenterReturn, nil
64 } 64 }
65 65
66 //发送短信验证码 66 //发送短信验证码
@@ -150,8 +150,8 @@ func RequestUCenterRestPassword(phone, newPwd, confirmPwd, certificate string) e @@ -150,8 +150,8 @@ func RequestUCenterRestPassword(phone, newPwd, confirmPwd, certificate string) e
150 log.Error("统一用户中心请求失败 err:%s", err) 150 log.Error("统一用户中心请求失败 err:%s", err)
151 return protocol.NewErrWithMessage("1") 151 return protocol.NewErrWithMessage("1")
152 } 152 }
153 - var ucenterReturn *CommResponse  
154 - err = json.Unmarshal(btBody, ucenterReturn) 153 + var ucenterReturn CommResponse
  154 + err = json.Unmarshal(btBody, &ucenterReturn)
155 if err != nil { 155 if err != nil {
156 log.Error("解析统一用户中心响应失败 err:%s", err) 156 log.Error("解析统一用户中心响应失败 err:%s", err)
157 return protocol.NewErrWithMessage("1") 157 return protocol.NewErrWithMessage("1")