作者 唐旭辉

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

... ... @@ -7,6 +7,7 @@ import (
"oppmg/protocol"
serveaudit "oppmg/services/audit"
servecommon "oppmg/services/common"
serverbac "oppmg/services/rbac"
"strconv"
"time"
)
... ... @@ -63,7 +64,7 @@ func (c *AuditController) AuditListBefore() {
defer func() {
c.ResposeJson(msg)
}()
// uid := c.GetUserId()
uid := c.GetUserId()
companyId := c.GetCompanyId()
templatelist := servecommon.SelectGetTemplateList(companyId)
chanceTypeList := servecommon.SeleteGetChanceTypeList(companyId)
... ... @@ -71,6 +72,10 @@ func (c *AuditController) AuditListBefore() {
publicStatus := models.ChancePublishStatusMap
Status := models.ChanceStatusMap
reviewStatus := models.ChanceReviewStatusMap
var (
auditPermission serverbac.OptionOpportunity
)
auditPermission = serveaudit.GetPermissionInAuditPage(uid, companyId)
data := map[string]interface{}{
"template": templatelist,
"chance_type": chanceTypeList,
... ... @@ -78,6 +83,7 @@ func (c *AuditController) AuditListBefore() {
"enable_status": Status,
"review_status": reviewStatus,
"department": departmentList,
"permission": auditPermission,
}
msg = protocol.NewReturnResponse(data, nil)
return
... ...
... ... @@ -2,6 +2,7 @@ package audit
import (
"encoding/json"
"errors"
"fmt"
"oppmg/common/log"
"oppmg/models"
... ... @@ -21,7 +22,7 @@ type SqlData struct {
AuditTemplateId int64 `orm:"column(audit_template_id)"`
ChanceTypeId int `orm:"column(chance_type_id)"`
PublishStatus int `orm:"column(publish_status)"`
CreateAt string `orm:"column(create_at)`
CreateAt string `orm:"column(create_at)"`
ReviewStatus int8 `orm:"column(review_status)"`
Status int8 `orm:"column(status)"`
DiscoveryScore string `orm:"column(discovery_score)"`
... ... @@ -29,6 +30,35 @@ type SqlData struct {
Code string `orm:"column(code)"`
}
func getAuditUserHasPermission(userid int64, usercompanyid int64) (
serverabc.PermissionOptionObject, error) {
var permissionObject serverabc.PermissionOptionObject
var err error
if ok := redisdata.ExistUserPermission(userid); !ok {
//尝试重数据库获取
log.Debug("从数据库读取权限")
permissionMap, err := serverabc.GetUserPermission(usercompanyid, serverabc.M_SYSTEM_OPPORTUNITY)
if err != nil {
log.Debug("从数据库未获得对应权限 :%s", err)
return nil, err
}
if v, ok := permissionMap[serverabc.M_SYSTEM_OPPORTUNITY]; !ok {
return nil, errors.New("can not found object")
} else {
permissionObject = v
}
} else {
//使用缓存
log.Debug("从缓存读取权限")
permissionObject, err = redisdata.GetUserPermission(userid, serverabc.M_SYSTEM_OPPORTUNITY)
if err != nil {
log.Debug("从缓存未获得对应权限 :%s", err)
return nil, err
}
}
return permissionObject, nil
}
//根据权限获取机会列表
func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) string {
/*
... ... @@ -63,32 +93,38 @@ func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) st
permissionObject serverabc.PermissionOptionObject
err error
)
//获取权限
if ok := redisdata.ExistUserPermission(userid); !ok {
//尝试重数据库获取
log.Debug("从数据库读取权限")
permissionMap, err := serverabc.GetUserPermission(usercompanyid, serverabc.M_SYSTEM_OPPORTUNITY)
if err != nil {
log.Debug("从数据库未获得对应权限 :%s", err)
unionsql = sql1 + " UNION " + sql2
return fmt.Sprintf(allsql, unionsql)
}
if v, ok := permissionMap[serverabc.M_SYSTEM_OPPORTUNITY]; !ok {
unionsql = sql1 + " UNION " + sql2
return fmt.Sprintf(allsql, unionsql)
} else {
permissionObject = v
}
} else {
//使用缓存
log.Debug("从缓存读取权限")
permissionObject, err = redisdata.GetUserPermission(userid, serverabc.M_SYSTEM_OPPORTUNITY)
if err != nil {
log.Debug("从缓存未获得对应权限 :%s", err)
unionsql = sql1 + " UNION " + sql2
return fmt.Sprintf(allsql, unionsql)
}
//---------------------------------
if permissionObject, err = getAuditUserHasPermission(usercompanyid, userid); err != nil {
unionsql = sql1 + " UNION " + sql2
return fmt.Sprintf(allsql, unionsql)
}
// //获取权限
// if ok := redisdata.ExistUserPermission(userid); !ok {
// //尝试重数据库获取
// log.Debug("从数据库读取权限")
// permissionMap, err := serverabc.GetUserPermission(usercompanyid, serverabc.M_SYSTEM_OPPORTUNITY)
// if err != nil {
// log.Debug("从数据库未获得对应权限 :%s", err)
// unionsql = sql1 + " UNION " + sql2
// return fmt.Sprintf(allsql, unionsql)
// }
// if v, ok := permissionMap[serverabc.M_SYSTEM_OPPORTUNITY]; !ok {
// unionsql = sql1 + " UNION " + sql2
// return fmt.Sprintf(allsql, unionsql)
// } else {
// permissionObject = v
// }
// } else {
// //使用缓存
// log.Debug("从缓存读取权限")
// permissionObject, err = redisdata.GetUserPermission(userid, serverabc.M_SYSTEM_OPPORTUNITY)
// if err != nil {
// log.Debug("从缓存未获得对应权限 :%s", err)
// unionsql = sql1 + " UNION " + sql2
// return fmt.Sprintf(allsql, unionsql)
// }
// }
// -------------------------
var (
usrPermission *serverabc.OptionOpportunity
ok bool
... ... @@ -475,3 +511,43 @@ func ForbidChanceEnableStatus(chanceid int64, companyid int64) error {
}
return nil
}
//获取用户在机会管理中的权限
func GetPermissionInAuditPage(userid int64, companyid int64) serverabc.OptionOpportunity {
var (
option serverabc.OptionOpportunity
err error
ucompany *models.UserCompany
companyinfo *models.Company
)
companyinfo, err = models.GetCompanyById(companyid)
if err != nil {
log.Error("GetCompanyById err:%s", err)
return option
}
if companyinfo.AdminId == userid {
option = serverabc.OptionOpportunity{
Check: serverabc.OpportunityCheckLv4,
EditSorce: 1,
EditPublicStatus: 1,
CloseChance: 1,
EditChance: 1,
}
return option
}
ucompany, err = models.GetUserCompanyBy(userid, companyid)
if err != nil {
log.Error("获取用户数据失败:GetUserCompanyBy err:%s", err)
return option
}
permissionobj, err := getAuditUserHasPermission(userid, ucompany.Id)
if err != nil {
return option
}
if v, ok := permissionobj.(*serverabc.OptionOpportunity); ok {
option = *v
option.CheckMap = nil
option.CheckOption = nil
}
return option
}
... ...
... ... @@ -123,7 +123,7 @@ var (
func NewOptionOpportunity() PermissionOptionObject {
return &OptionOpportunity{
Check: OpportunityCheckLv1,
Check: OpportunityCheckLv2,
CheckMap: make(map[int]int),
CheckOption: &CheckOpp{
Departments: []CheckDeparment{},
... ...