|
|
@@ -722,56 +722,45 @@ func (d *WorkOrderDao) DataScope(ctx context.Context, args ...interface{}) *Work
|
|
|
cs := ctx.Value("contextService")
|
|
|
dataScope := gconv.Map(gconv.String(gconv.Map(cs)["dataScope"]))
|
|
|
if dataScope != nil {
|
|
|
- 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 + "."
|
|
|
+ // 销售工程师判断
|
|
|
+ var salesEngineerFlag bool
|
|
|
+ if roles, ok := dataScope["roles"]; ok {
|
|
|
+ arr := garray.NewArrayFrom(roles.([]interface{}), true)
|
|
|
+ if arr.Len() == 1 && arr.Contains("SalesEngineer") {
|
|
|
+ salesEngineerFlag = true
|
|
|
}
|
|
|
}
|
|
|
userIds, ok := dataScope["userIds"]
|
|
|
- delete(dataScope, "userIds")
|
|
|
+ specialFlag, userCols, orColsMap := d.checkColumnsName(dataScope, args)
|
|
|
+
|
|
|
var orColumns []string
|
|
|
var orValues []interface{}
|
|
|
if ok && userIds != "-1" {
|
|
|
- column := "created_by"
|
|
|
- if len(args) > 0 {
|
|
|
- column = args[0].(string)
|
|
|
+ columns := []string{"created_by"}
|
|
|
+ if len(userCols) > 0 {
|
|
|
+ columns = userCols
|
|
|
}
|
|
|
- if ok, _ := d.M.HasField(column); ok || specialFlag {
|
|
|
- orColumns = append(orColumns, tableAs+column+" IN (?) ")
|
|
|
- orValues = append(orValues, userIds)
|
|
|
+ for _, column := range columns {
|
|
|
+ if ok, _ := d.M.HasField(column); ok || specialFlag {
|
|
|
+ orColumns = append(orColumns, column+" IN (?) ")
|
|
|
+ orValues = append(orValues, userIds)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- // 销售工程师判断
|
|
|
- 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
|
|
|
+ for col, params := range orColsMap {
|
|
|
+ if ok, _ := d.M.HasField(col); ok || specialFlag {
|
|
|
+ orColumns = append(orColumns, col+" IN (?) ")
|
|
|
+ orValues = append(orValues, params)
|
|
|
}
|
|
|
}
|
|
|
- // 非销售工程师权限加成
|
|
|
+
|
|
|
+ // 销售工程师权限加成
|
|
|
if !salesEngineerFlag {
|
|
|
- bigColumns := "is_big"
|
|
|
- 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)
|
|
|
- }
|
|
|
- delete(dataScope, bigColumns)
|
|
|
- }
|
|
|
var andColumns []string
|
|
|
var andValues []interface{}
|
|
|
for k, v := range dataScope {
|
|
|
if ok, _ := d.M.HasField(k); ok || specialFlag {
|
|
|
- andColumns = append(andColumns, tableAs+k+" IN (?) ")
|
|
|
+ andColumns = append(andColumns, k+" IN (?) ")
|
|
|
andValues = append(andValues, v)
|
|
|
}
|
|
|
}
|
|
|
@@ -787,3 +776,76 @@ func (d *WorkOrderDao) DataScope(ctx context.Context, args ...interface{}) *Work
|
|
|
}
|
|
|
return d
|
|
|
}
|
|
|
+
|
|
|
+// args 1、字段
|
|
|
+// args 2、字段、表名
|
|
|
+// args 3、字段对应关系
|
|
|
+func (d *WorkOrderDao) checkColumnsName(dataScope map[string]interface{}, args ...interface{}) (bool, []string, map[string]interface{}) {
|
|
|
+ var tableAs string
|
|
|
+ var specialFlag bool
|
|
|
+ var userCols []string
|
|
|
+ var orColsMap map[string]interface{}
|
|
|
+ var colsContrast map[string]interface{}
|
|
|
+
|
|
|
+ if d.TableAs != "" && len(args) <= 1 {
|
|
|
+ tableAs = d.TableAs + "."
|
|
|
+ }
|
|
|
+ if len(args) > 1 {
|
|
|
+ specialFlag = true
|
|
|
+ if val, ok := args[1].(string); ok {
|
|
|
+ tableAs = val + "."
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(args) > 0 {
|
|
|
+ if column, ok := args[0].(string); ok {
|
|
|
+ userCols = []string{tableAs + column}
|
|
|
+ }
|
|
|
+ if cols, ok := args[0].([]string); ok {
|
|
|
+ for _, v := range cols {
|
|
|
+ userCols = append(userCols, tableAs+v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if val, ok := args[0].(map[string]interface{}); ok {
|
|
|
+ specialFlag = true
|
|
|
+ colsContrast = val
|
|
|
+ if orcols, ok := val["orcols"]; ok && val[orcols.(string)] != "" {
|
|
|
+ if col, ok := orcols.(string); ok && gconv.String(val[col]) != "" {
|
|
|
+ orColsMap[col] = val[col]
|
|
|
+ delete(colsContrast, col)
|
|
|
+ }
|
|
|
+ if cols, ok := orcols.([]string); ok {
|
|
|
+ for _, col := range cols {
|
|
|
+ if gconv.String(val[col]) == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ orColsMap[col] = val[col]
|
|
|
+ delete(colsContrast, col)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bigColumns := "is_big"
|
|
|
+ if isBig, ok := dataScope[bigColumns]; ok && isBig.(bool) {
|
|
|
+ if bigCol, ok := colsContrast[bigColumns]; ok {
|
|
|
+ orColsMap[bigCol.(string)] = isBig
|
|
|
+ delete(colsContrast, bigCol.(string))
|
|
|
+ } else {
|
|
|
+ orColsMap[tableAs+bigColumns] = isBig
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ delete(dataScope, "userIds")
|
|
|
+ delete(dataScope, "roles")
|
|
|
+ delete(dataScope, "posts")
|
|
|
+ delete(dataScope, bigColumns)
|
|
|
+ for k, v := range colsContrast {
|
|
|
+ if data, ok := dataScope[k]; ok {
|
|
|
+ dataScope[v.(string)] = data
|
|
|
+ delete(dataScope, k)
|
|
|
+ } else {
|
|
|
+ dataScope[k] = v
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return specialFlag, userCols, orColsMap
|
|
|
+}
|