|
|
@@ -694,13 +694,20 @@ func (d *ProjBusinessDynamicsDao) Unscoped() *ProjBusinessDynamicsDao {
|
|
|
}
|
|
|
|
|
|
// DataScope enables the DataScope feature.
|
|
|
-func (d *ProjBusinessDynamicsDao) DataScope(ctx context.Context, userCol ...string) *ProjBusinessDynamicsDao {
|
|
|
+func (d *ProjBusinessDynamicsDao) DataScope(ctx context.Context, args ...interface{}) *ProjBusinessDynamicsDao {
|
|
|
cs := ctx.Value("contextService")
|
|
|
- dataScope := gconv.Map(cs)["dataScope"].(g.Map)
|
|
|
+ dataScope := gconv.Map(gconv.String(gconv.Map(cs)["dataScope"]))
|
|
|
if dataScope != nil {
|
|
|
- tableAs := d.TableAs
|
|
|
- if d.TableAs != "" {
|
|
|
- tableAs += "."
|
|
|
+ var specialFlag bool
|
|
|
+ var tableAs string
|
|
|
+ if d.TableAs != "" && len(args) <= 1 {
|
|
|
+ tableAs = d.TableAs + "."
|
|
|
+ }
|
|
|
+ if len(args) > 1 {
|
|
|
+ specialFlag = true
|
|
|
+ if val, ok := args[1].(string); ok {
|
|
|
+ tableAs = val + "."
|
|
|
+ }
|
|
|
}
|
|
|
userIds, ok := dataScope["userIds"]
|
|
|
delete(dataScope, "userIds")
|
|
|
@@ -708,10 +715,10 @@ func (d *ProjBusinessDynamicsDao) DataScope(ctx context.Context, userCol ...stri
|
|
|
var orValues []interface{}
|
|
|
if ok && userIds != "-1" {
|
|
|
column := "created_by"
|
|
|
- if len(userCol) == 1 {
|
|
|
- column = userCol[0]
|
|
|
+ if len(args) > 0 {
|
|
|
+ column = args[0].(string)
|
|
|
}
|
|
|
- if ok, _ := d.M.HasField(column); ok {
|
|
|
+ if ok, _ := d.M.HasField(column); ok || specialFlag {
|
|
|
orColumns = append(orColumns, tableAs+column+" IN (?) ")
|
|
|
orValues = append(orValues, userIds)
|
|
|
}
|
|
|
@@ -719,6 +726,8 @@ func (d *ProjBusinessDynamicsDao) DataScope(ctx context.Context, userCol ...stri
|
|
|
// 销售工程师判断
|
|
|
var salesEngineerFlag bool
|
|
|
if roles, ok := dataScope["roles"]; ok {
|
|
|
+ delete(dataScope, "roles")
|
|
|
+ delete(dataScope, "posts")
|
|
|
arr := garray.NewArrayFrom(roles.([]interface{}), true)
|
|
|
if arr.Len() == 1 && arr.Contains("SalesEngineer") {
|
|
|
salesEngineerFlag = true
|
|
|
@@ -727,7 +736,7 @@ func (d *ProjBusinessDynamicsDao) DataScope(ctx context.Context, userCol ...stri
|
|
|
// 非销售工程师权限加成
|
|
|
if !salesEngineerFlag {
|
|
|
bigColumns := "is_big"
|
|
|
- if ok, _ := d.M.HasField("is_big"); ok {
|
|
|
+ if ok, _ := d.M.HasField("is_big"); ok || specialFlag {
|
|
|
if val, ok := dataScope[bigColumns]; ok && val != "" {
|
|
|
orColumns = append(orColumns, tableAs+bigColumns+" = ? ")
|
|
|
orValues = append(orValues, val)
|
|
|
@@ -737,7 +746,7 @@ func (d *ProjBusinessDynamicsDao) DataScope(ctx context.Context, userCol ...stri
|
|
|
var andColumns []string
|
|
|
var andValues []interface{}
|
|
|
for k, v := range dataScope {
|
|
|
- if ok, _ := d.M.HasField(k); ok {
|
|
|
+ if ok, _ := d.M.HasField(k); ok || specialFlag {
|
|
|
andColumns = append(andColumns, tableAs+k+" IN (?) ")
|
|
|
andValues = append(andValues, v)
|
|
|
}
|