作者 唐旭辉

机会列表前置 输出数据修改

@@ -7,6 +7,7 @@ import ( @@ -7,6 +7,7 @@ import (
7 "oppmg/protocol" 7 "oppmg/protocol"
8 serveaudit "oppmg/services/audit" 8 serveaudit "oppmg/services/audit"
9 servecommon "oppmg/services/common" 9 servecommon "oppmg/services/common"
  10 + serverbac "oppmg/services/rbac"
10 "strconv" 11 "strconv"
11 "time" 12 "time"
12 ) 13 )
@@ -63,7 +64,7 @@ func (c *AuditController) AuditListBefore() { @@ -63,7 +64,7 @@ func (c *AuditController) AuditListBefore() {
63 defer func() { 64 defer func() {
64 c.ResposeJson(msg) 65 c.ResposeJson(msg)
65 }() 66 }()
66 - // uid := c.GetUserId() 67 + uid := c.GetUserId()
67 companyId := c.GetCompanyId() 68 companyId := c.GetCompanyId()
68 templatelist := servecommon.SelectGetTemplateList(companyId) 69 templatelist := servecommon.SelectGetTemplateList(companyId)
69 chanceTypeList := servecommon.SeleteGetChanceTypeList(companyId) 70 chanceTypeList := servecommon.SeleteGetChanceTypeList(companyId)
@@ -71,6 +72,10 @@ func (c *AuditController) AuditListBefore() { @@ -71,6 +72,10 @@ func (c *AuditController) AuditListBefore() {
71 publicStatus := models.ChancePublishStatusMap 72 publicStatus := models.ChancePublishStatusMap
72 Status := models.ChanceStatusMap 73 Status := models.ChanceStatusMap
73 reviewStatus := models.ChanceReviewStatusMap 74 reviewStatus := models.ChanceReviewStatusMap
  75 + var (
  76 + auditPermission serverbac.OptionOpportunity
  77 + )
  78 + auditPermission = serveaudit.GetPermissionInAuditPage(uid, companyId)
74 data := map[string]interface{}{ 79 data := map[string]interface{}{
75 "template": templatelist, 80 "template": templatelist,
76 "chance_type": chanceTypeList, 81 "chance_type": chanceTypeList,
@@ -78,6 +83,7 @@ func (c *AuditController) AuditListBefore() { @@ -78,6 +83,7 @@ func (c *AuditController) AuditListBefore() {
78 "enable_status": Status, 83 "enable_status": Status,
79 "review_status": reviewStatus, 84 "review_status": reviewStatus,
80 "department": departmentList, 85 "department": departmentList,
  86 + "permission": auditPermission,
81 } 87 }
82 msg = protocol.NewReturnResponse(data, nil) 88 msg = protocol.NewReturnResponse(data, nil)
83 return 89 return
@@ -2,6 +2,7 @@ package audit @@ -2,6 +2,7 @@ package audit
2 2
3 import ( 3 import (
4 "encoding/json" 4 "encoding/json"
  5 + "errors"
5 "fmt" 6 "fmt"
6 "oppmg/common/log" 7 "oppmg/common/log"
7 "oppmg/models" 8 "oppmg/models"
@@ -21,7 +22,7 @@ type SqlData struct { @@ -21,7 +22,7 @@ type SqlData struct {
21 AuditTemplateId int64 `orm:"column(audit_template_id)"` 22 AuditTemplateId int64 `orm:"column(audit_template_id)"`
22 ChanceTypeId int `orm:"column(chance_type_id)"` 23 ChanceTypeId int `orm:"column(chance_type_id)"`
23 PublishStatus int `orm:"column(publish_status)"` 24 PublishStatus int `orm:"column(publish_status)"`
24 - CreateAt string `orm:"column(create_at)` 25 + CreateAt string `orm:"column(create_at)"`
25 ReviewStatus int8 `orm:"column(review_status)"` 26 ReviewStatus int8 `orm:"column(review_status)"`
26 Status int8 `orm:"column(status)"` 27 Status int8 `orm:"column(status)"`
27 DiscoveryScore string `orm:"column(discovery_score)"` 28 DiscoveryScore string `orm:"column(discovery_score)"`
@@ -29,6 +30,35 @@ type SqlData struct { @@ -29,6 +30,35 @@ type SqlData struct {
29 Code string `orm:"column(code)"` 30 Code string `orm:"column(code)"`
30 } 31 }
31 32
  33 +func getAuditUserHasPermission(userid int64, usercompanyid int64) (
  34 + serverabc.PermissionOptionObject, error) {
  35 + var permissionObject serverabc.PermissionOptionObject
  36 + var err error
  37 + if ok := redisdata.ExistUserPermission(userid); !ok {
  38 + //尝试重数据库获取
  39 + log.Debug("从数据库读取权限")
  40 + permissionMap, err := serverabc.GetUserPermission(usercompanyid, serverabc.M_SYSTEM_OPPORTUNITY)
  41 + if err != nil {
  42 + log.Debug("从数据库未获得对应权限 :%s", err)
  43 + return nil, err
  44 + }
  45 + if v, ok := permissionMap[serverabc.M_SYSTEM_OPPORTUNITY]; !ok {
  46 + return nil, errors.New("can not found object")
  47 + } else {
  48 + permissionObject = v
  49 + }
  50 + } else {
  51 + //使用缓存
  52 + log.Debug("从缓存读取权限")
  53 + permissionObject, err = redisdata.GetUserPermission(userid, serverabc.M_SYSTEM_OPPORTUNITY)
  54 + if err != nil {
  55 + log.Debug("从缓存未获得对应权限 :%s", err)
  56 + return nil, err
  57 + }
  58 + }
  59 + return permissionObject, nil
  60 +}
  61 +
32 //根据权限获取机会列表 62 //根据权限获取机会列表
33 func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) string { 63 func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) string {
34 /* 64 /*
@@ -63,32 +93,38 @@ func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) st @@ -63,32 +93,38 @@ func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) st
63 permissionObject serverabc.PermissionOptionObject 93 permissionObject serverabc.PermissionOptionObject
64 err error 94 err error
65 ) 95 )
66 - //获取权限  
67 - if ok := redisdata.ExistUserPermission(userid); !ok {  
68 - //尝试重数据库获取  
69 - log.Debug("从数据库读取权限")  
70 - permissionMap, err := serverabc.GetUserPermission(usercompanyid, serverabc.M_SYSTEM_OPPORTUNITY)  
71 - if err != nil {  
72 - log.Debug("从数据库未获得对应权限 :%s", err)  
73 - unionsql = sql1 + " UNION " + sql2  
74 - return fmt.Sprintf(allsql, unionsql)  
75 - }  
76 - if v, ok := permissionMap[serverabc.M_SYSTEM_OPPORTUNITY]; !ok {  
77 - unionsql = sql1 + " UNION " + sql2  
78 - return fmt.Sprintf(allsql, unionsql)  
79 - } else {  
80 - permissionObject = v  
81 - }  
82 - } else {  
83 - //使用缓存  
84 - log.Debug("从缓存读取权限")  
85 - permissionObject, err = redisdata.GetUserPermission(userid, serverabc.M_SYSTEM_OPPORTUNITY)  
86 - if err != nil {  
87 - log.Debug("从缓存未获得对应权限 :%s", err)  
88 - unionsql = sql1 + " UNION " + sql2  
89 - return fmt.Sprintf(allsql, unionsql)  
90 - } 96 + //---------------------------------
  97 + if permissionObject, err = getAuditUserHasPermission(usercompanyid, userid); err != nil {
  98 + unionsql = sql1 + " UNION " + sql2
  99 + return fmt.Sprintf(allsql, unionsql)
91 } 100 }
  101 + // //获取权限
  102 + // if ok := redisdata.ExistUserPermission(userid); !ok {
  103 + // //尝试重数据库获取
  104 + // log.Debug("从数据库读取权限")
  105 + // permissionMap, err := serverabc.GetUserPermission(usercompanyid, serverabc.M_SYSTEM_OPPORTUNITY)
  106 + // if err != nil {
  107 + // log.Debug("从数据库未获得对应权限 :%s", err)
  108 + // unionsql = sql1 + " UNION " + sql2
  109 + // return fmt.Sprintf(allsql, unionsql)
  110 + // }
  111 + // if v, ok := permissionMap[serverabc.M_SYSTEM_OPPORTUNITY]; !ok {
  112 + // unionsql = sql1 + " UNION " + sql2
  113 + // return fmt.Sprintf(allsql, unionsql)
  114 + // } else {
  115 + // permissionObject = v
  116 + // }
  117 + // } else {
  118 + // //使用缓存
  119 + // log.Debug("从缓存读取权限")
  120 + // permissionObject, err = redisdata.GetUserPermission(userid, serverabc.M_SYSTEM_OPPORTUNITY)
  121 + // if err != nil {
  122 + // log.Debug("从缓存未获得对应权限 :%s", err)
  123 + // unionsql = sql1 + " UNION " + sql2
  124 + // return fmt.Sprintf(allsql, unionsql)
  125 + // }
  126 + // }
  127 + // -------------------------
92 var ( 128 var (
93 usrPermission *serverabc.OptionOpportunity 129 usrPermission *serverabc.OptionOpportunity
94 ok bool 130 ok bool
@@ -475,3 +511,43 @@ func ForbidChanceEnableStatus(chanceid int64, companyid int64) error { @@ -475,3 +511,43 @@ func ForbidChanceEnableStatus(chanceid int64, companyid int64) error {
475 } 511 }
476 return nil 512 return nil
477 } 513 }
  514 +
  515 +//获取用户在机会管理中的权限
  516 +func GetPermissionInAuditPage(userid int64, companyid int64) serverabc.OptionOpportunity {
  517 + var (
  518 + option serverabc.OptionOpportunity
  519 + err error
  520 + ucompany *models.UserCompany
  521 + companyinfo *models.Company
  522 + )
  523 + companyinfo, err = models.GetCompanyById(companyid)
  524 + if err != nil {
  525 + log.Error("GetCompanyById err:%s", err)
  526 + return option
  527 + }
  528 + if companyinfo.AdminId == userid {
  529 + option = serverabc.OptionOpportunity{
  530 + Check: serverabc.OpportunityCheckLv4,
  531 + EditSorce: 1,
  532 + EditPublicStatus: 1,
  533 + CloseChance: 1,
  534 + EditChance: 1,
  535 + }
  536 + return option
  537 + }
  538 + ucompany, err = models.GetUserCompanyBy(userid, companyid)
  539 + if err != nil {
  540 + log.Error("获取用户数据失败:GetUserCompanyBy err:%s", err)
  541 + return option
  542 + }
  543 + permissionobj, err := getAuditUserHasPermission(userid, ucompany.Id)
  544 + if err != nil {
  545 + return option
  546 + }
  547 + if v, ok := permissionobj.(*serverabc.OptionOpportunity); ok {
  548 + option = *v
  549 + option.CheckMap = nil
  550 + option.CheckOption = nil
  551 + }
  552 + return option
  553 +}
@@ -123,7 +123,7 @@ var ( @@ -123,7 +123,7 @@ var (
123 123
124 func NewOptionOpportunity() PermissionOptionObject { 124 func NewOptionOpportunity() PermissionOptionObject {
125 return &OptionOpportunity{ 125 return &OptionOpportunity{
126 - Check: OpportunityCheckLv1, 126 + Check: OpportunityCheckLv2,
127 CheckMap: make(map[int]int), 127 CheckMap: make(map[int]int),
128 CheckOption: &CheckOpp{ 128 CheckOption: &CheckOpp{
129 Departments: []CheckDeparment{}, 129 Departments: []CheckDeparment{},